Get list of project name, project lead, project key using java api

quocdung3007 October 20, 2016

Hi,

I'm trying to use Java API to get a list project name, project lead, project key by using groovy ScriptRunner. Do you have any example of my queries.

Thanks.

2 answers

4 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 21, 2016

Hi Dung,

You can do this using the project manager and looping over the projectObjects to get the information that you require.

I have attached a sample script that you can modify along with a screenshot of what its output looks like.

Script:

import com.atlassian.jira.component.ComponentAccessor

// Get the Project Manager
def projectManager = ComponentAccessor.getProjectManager()

// Iterate over each Project Object
def project = projectManager.getProjectObjects().each {project->
}

// Return information for each project object
return "Project Names: " + "<br/>" +  project.name + "<br/>" + "Project Keys: " + "<br/>" +  project.key + "<br/>" + "Project Leads: " + "<br/>" +  project.lead.name

Sample Output:

Screen Shot 2016-10-21 at 15.57.42.png

I hope this helps.

Kristian

1 vote
Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 20, 2016

Here is an example. Cheers!

import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.*
import com.atlassian.jira.user.ApplicationUsers        
import java.util.Collections

Project myProject = issue.getProjectObject()
def leads 
def projectName, projectKey
 
leads = myProject.getProjectLead()
projectName = issue.getProjectObject().getName();
projectKey = issue.getProjectObject().getKey();
return "projectName is " + projectName + ", Project Key is " + projectKey+ ", Leads are " + leads
quocdung3007 October 20, 2016

Hi Mahesh,

Thanks. But what I need is to get all the projects. As I understand, your code need to have issue object to the project name, project lead and key.

I want to run the code in Script Console.

Mahesh S
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 21, 2016
Like Barbara Post likes this

Suggest an answer

Log in or Sign up to answer