Sample code for retrieving a project metadata

First of all thanks Andreas for such nice plugin.

After some hours of trying I made working using Script Runner for getting a metadata ("mykey") from given project ("RISK")

Just want to share it with you this short snippet to save your time, I hope it helps :)

Regards,

Jarda

import com.atlassian.jira.ComponentManager
import com.atlassian.plugin.osgi.container.OsgiContainerManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.component.ComponentAccessor


Project project = ComponentAccessor.getProjectManager().getProjectObjByKey("RISK");

OsgiContainerManager osgiManager = ComponentManager.getInstance().getComponentInstanceOfType(OsgiContainerManager.class)

String x = osgiManager.getServiceTracker("com.osoboo.jira.metadata.MetadataService").getService().getMetadataValue(project, "mykey")

 

3 comments

Good stuff!

 

Do you know if you can get the metadata out using the existing JIRA API?

Thx, not to my knowledge :(

It's' unfortunate that the groovy embedded "compiler" gives  you a potential error in the script, but it works when running a preview on an issue.  Thanks!!!!!

Is there a way to write this in java?

My understanding is that GROOVY script is Java with some "fluff".  And that GROOVY follows almost all, if not all the syntax conventions of JAVA.  Which part isn't working for you the way it's written in groovy

I guess in order to make it work in JAVA you may have to wrap it in a class to get it to execute?

Thanks Phillip. I realized that the metadata plugin is not free anymore so we're not going to install int anymore on the latest Jira version we are upgrading to soon. We are going to use the Project Properties Plugin for Jira as a replacement.

Really? That's the third plugin I remember which used to be free and became paid. Damn it, we run 10k license :( 

Comment

Log in or Sign up to comment
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,739 views 3 11
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