Hi,
Using the groovy script runner, I get the following working:
import com.atlassian.jira.ComponentManager def projectManager = ComponentManager.getInstance().getProjectManager() def result=""; result += "Key, Name, Lead\n"; for(p in projectManager.projectObjects) { result += "$p.key, $p.name, $p.lead\n"; } return result;
I would like to add for each project, the users that are assigned a certain project role. I know that for this specific project role only 1 user is assigned, never a group if that would make it easier to do.
I looked at http://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/project/Project.html to see what is possible, but I could not find anything related to project roles there.
regards,
Wim
Community moderators have prevented the ability to post new answers.
Try this:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.project.Project import com.atlassian.jira.project.ProjectManager import com.atlassian.jira.security.roles.ProjectRole import com.atlassian.jira.security.roles.ProjectRoleActors import com.atlassian.jira.security.roles.ProjectRoleManager ComponentManager componentManager = ComponentManager.getInstance() ProjectManager projectManager = componentManager.getProjectManager() ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager // name of role here ProjectRole devsRole = projectRoleManager.getProjectRole("Developers") projectManager.getProjectObjects().each {Project project -> ProjectRoleActors actors = projectRoleManager.getProjectRoleActors(devsRole, project) log.debug "$project.key, $project.name, $project.lead, ${actors.getUsers()*.name}\n"; // if there is only one member of the role or you only want the first you could do: log.debug actors.getUsers().toList()?.first()?.name }
Odd that I got a mail saying my answer had been accepted but here there is no tick.... wondering how that happened.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just accepted again, tick seems to be there now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie. I tried this script in Script Console and it return all the project keys. Below is the output. But I want something project name and all the users in the roles of that project. I want this for multiple projects based on project category. Is it possible? Also will I be able to display the output somewhere other than below the script console? Sorry lot of questions
Output is something like this:
[Project: EEOS, Project: CPRM, Project: AAGS, Project: AAT, Project: CTO, Project: AGI, Project: AGILE, Project: SBGZZ, Project: AINN, Project: AGPG, Project: AGLT, Project: MAI, Project: TERMS, Project: RPPL, Project: AND, Project: ANPF, Project: SPO, Project: SPOA, Project: CSM, Project: ADC, Project: CDPMAHTAB, Project: LMA, Project: LM, Project: TRM, Project: TOMCCA]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it returns the project objects, but the role data is logged using log.debug. Change it to log.warn then check your logs. This is just example code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got this error too.. Don't know why !
java.util.NoSuchElementException: Cannot access first() element from an empty List at Script92$_run_closure1.doCall(Script92.groovy:20) at Script92.run(Script92.groovy:15)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The code has some depricated items. Can't get it to work with Jira Server v7.12.
I'm not an expert on writing code but do need a list of Users with their projectrole.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I agree. I am using JIRA v8.1.2 and some of the classes used in the above script don't work anymore. I believe those classes have been removed. Please update.
Thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.