So far I have got a script which returns all of the users in my test instance of JIRA.
I have also added to the script so that it is able to get all of the groups too.
However, this is quite basic and I would like to know how people use Groovy in order to retrieve more information (for example: Email, Fullname, login time, project roles and groups they're in etc).
I've been looking through the documentation but I'm feeling somewhat overwhelemed with the different classes and libraries to do different asks.
If anybody has any ideas, or could point my code in the right direction, that would be good.
Thanks
My script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.bc.user.search.UserSearchParams
import com.atlassian.jira.web.action.admin.roles.AbstractProjectRole
import com.atlassian.jira.bc.group.search.GroupPickerSearchService
import com.atlassian.crowd.embedded.api.Group
def userSearchService = ComponentAccessor.getComponent(UserSearchService.class);
UserSearchParams userSearchParams = (new UserSearchParams.Builder()).allowEmptyQuery(true).includeActive(true).includeInactive(true).maxResults(100000).build();
userSearchService.findUsers("", userSearchParams).each{ it->
log.error(it.getKey())
}
def groupSearchService = ComponentAccessor.getComponent(GroupPickerSearchService);
def groupArray = groupSearchService.findGroups("")
def groupManager = ComponentAccessor.getGroupManager()
for(Group group in groupArray){
log.error group.getName().toString()
}
You can use ComponentAccessor
def groupManger = ComponentAccessor.getGroupManager()
The for role you can use - ProjectRoleManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)
Group Manager has plenty of amazing methods to get deep insights into user group mapping.
https://docs.atlassian.com/DAC/javadoc/jira/7.1.0-m01/reference/com/atlassian/jira/security/roles/ProjectRoleManager.html#getProjectRoles(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.project.Project)
Each user is represented by "ApplicationUser" object which has methods like getEmailAddress() and getDisplayName()
You can get currentUser using
ComponentAccessor.getJiraAuthenticationContext()getLoggedInUser()
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.
For login related info for the user you can use the "LoginManager"
You can fetch an instance of this class using "ComponentAccessor.getComponent(LoginManager.class)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you! Are you aware of how you can get the users that are in each project?
I currently am using:
def projectSearchService = ComponentAccessor.getProjectManager()
def projectArray = projectSearchService.getProjectObjects()
log.error projectArray + " " + projectRoles
This provides me with the project codes, and the available roles in my JIRA project, however I would like a list of the users in each role within the project.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please see here
You will need to use ProjectRoleManager to get users for a specific role in a project. So you can create a for loop which goes over the list of roles and for each ieration fetch ProjecctRoleActors and then do getUsers()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.