Crafting a service with JIRA Metadata Plugin


Craft a service to refresh a certain set of project-level data in JIRA. (Version dates to be specific.) Fun facts about this service:

  • Will be crafted with Groovy Runner (cuz it's awesome)
  • Will run once a day
  • The source data is pulled from a database
  • This source data knows which project data to refresh through a a custom project field set by the JIRA Metadata Plugin.

And it's this plugin that's currently the crux of my question. I found this code snippet that explains the proper API call for the plugin, but it assumes you're calling it from a listener or post-function and not a service:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import org.apache.log4j.Category

OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class)
issue.setDescription(osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(issue.getProjectObject(), "accounting.code"))

What I'm really looking for is some API call with this plugin that returns an object of type Project when given a custom field name and custom field value.


  1. Does anyone know if I can use JIRA Metadata Plugin to accomplish my goal?
  2. If not, can anyone think of any creative solutions to accomplish my goal?

1 answer

1 accepted


1. your script-snipplet should work with Groovy Runner.

2. you should ask the ProjectManager to get the Project (Project Object)

e.g. ComponentManager.getInstance().getProjectManager().getProjectObjByKey("ProjectKey") (see: and

3. you can change the medatadata value (custom project field) via api call


osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().save(issue.getProjectObject(), "accounting.code", "the new value"); (see:

hope this will help you out


Thanks, Andreas. We're getting there, but it's not quite what I'm looking for. My source data contains a whole list of projects. This data is tied to the data in JIRA by a metadata field called "Theme Key." Ideally, I would make an API call via JIRA Metadata to a method looking something like this:

Project getProject (String customFieldName, String customFieldValue)

My code would never need to modify the metadata only use it to find which project to update. In short, this is what I want my code to do:

  1. Service starts.
  2. Service grabs first row of data from source database.
  3. Service figures out which project to update by finding the proper theme key.
    1. (This step right here is where I need that getProject API call I mentioned above.)
  4. Service updates some project-level information using JIRA's API.
  5. Service grabs next row of data. Go to Step 3.
  6. Service ends when all source data has been consumed.

Also, Andreas, by the looks of it, this guy might do the trick:

Collection<JiraMetadata> getMetadata(ObjectenrichedObject);
But that's only if:
  1. That collection can be unwrapped to return me the proper project.
  2. I can figure out how to properly feed it that enriched object.

The enriched object must be a project or version object. The collection will be all metadata values for this project/version object

You can iterate over all projects.something like:

for (Project p : ProjectManager.getProjectObjects()) {
if ("the value ".equals(metadataService.getMetadataValue(p, "theme"))) {

In that case, getMetadata won't do the trick. Is there anything in JIRA Metadata that will, Andreas?

brilliant. i hadn't thought to tackle the problem from the other direction. That should do nicely. Thank you!! :)

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


247 views 0 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you