Hi all,
We are trying to figure out a way to pull all users within multiple groups, and display their details via the scriptrunner console.
Example:
User 1 - Name, Email, All groups associated: (Group 1, Group 3, Group 5)
User 2 - Name, Email, All groups associated: (Group 2, Group 4, Group 5)
User 3 - Name, Email, All groups associated: (Group 1, Group 2, Group 4)
User 4 - Name, Email, All groups associated: (Group 1, Group 4, Group 5)
User 5 - Name, Email, All groups associated: (Group 2, Group 3, Group 4)
Goal:
If we run the script and want users details who are within both group 4 & group 5, we would hopefully get the following visual output:
User 2 - Name, Email, All groups associated: (Group 2, Group 4, Group 5)
User 4 - Name, Email, All groups associated: (Group 1, Group 4, Group 5)
Is this possible / does anyone know a script that can accomplish this?
Thanks,
Mike
For those who need to pull this type of reporting; we've figured it out, and the console prints our the user details in a nice HTML format so we can copy / paste the results into excel. (separated by";")
Please see below for the coding:
import com.adaptavist.hapi.jira.groups.Groups
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import groovy.xml.MarkupBuilder
//Define groups to pull from
def Group1 = Groups.getByName('Group1 Users')
def Group2 = Groups.getByName('Group2 Users')
def jiraUserGroup = Groups.getByName('jira-software-users')
//Extract members from the above defined groups
def Group1Members = Group1.members
def Group2Members = Group2.members
def jiraUserGroupMembers = jiraUserGroup.members
//Define 'grouping' to start from (IE: Users in jira-software-users)
def users = jiraUserGroupMembers
users.unique()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager)
//Only retain users who match the grouping logic below
users.retainAll {
it in Group1Members || it in Group2Members
}
def stringWriter = new StringWriter()
def content = new MarkupBuilder(stringWriter)
def groupManager = ComponentAccessor.groupManager
//Extract the username, display name, and email address for remaining users & display in html format
users.each {
def displayname = it.displayName
def username = it.username
def groups = groupManager.getGroupNamesForUser(username) as String[]
def email = it.emailAddress
def createdDate = it.createdDate
content.html{
p("${displayname};${createdDate};${username};${groups};${email}")
}
}
stringWriter.toString()
@Michael You might review this other option too: https://confluence.atlassian.com/jirakb/how-to-display-the-email-address-of-the-reporter-on-a-jira-issue-1188416840.html
HTH
Nicolas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again @Nicolas Grossi
That won't help us, as we aren't looking for reporters within tickets. We are looking for all active users within specific groups.
Any other suggestions would be greatly appreciated.
Thanks,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Michael you might take a look at this information link: https://community.atlassian.com/t5/Jira-questions/user-profile-information-using-script-runner/qaq-p/1798819
HTH
Nicolas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Nicolas,
we'll look at this and try to create some coding based on this. We'll reach back out if we still have questions.
Thanks again,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @Nicolas Grossi,
We've put together the following code, but we can't seem to get it to work correctly:
import com.adaptavist.hapi.jira.groups.Groups
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
def Group1 = Groups.getByName('Group 1 Users')
def Group2 = Groups.getByName('Group 2 Users')
def jiraUserGroup = Groups.getByName('jira-software-users')
def Group1Members = Group1.members
def Group2Members = Group2.members
def jiraUserGroupMembers = jiraUserGroup.members
def users = jiraUserGroupMembers
users.unique()
def loginManager = ComponentAccessor.getComponentOfType(LoginManager)
//Only include users in these groups.
users.addAll {
it in Group1Members || it in Group2Members
}
//take action on all remaining users
users.each {
def username = it.username
def fullname = it.displayName
def email = it.emailAddress
println("username: $username fullname: $fullname email: $email")
}
We are trying to pull the username, display name, and email for all members within the corresponding "group 1" and "group 2". Would you be able to point us in the correct direction?
Thanks,
Mike
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.