How to create Jira Group using distribution list(DL) without using existing LDAP configuration

Vijay Sv April 29, 2021

Hello Everyone!!

 

How can i achieve creating a Jira group with the list of users present in a distribution list(DL), note that already i have configured the LDAP group which i don't want to disturb and create a new group and manage at the project level. 

can we use script runner to create groups? 

Any suggestions would be appreciated!!

2 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2021

With scriptrunner ... if you can do something in the UI, its generally safe to assume you can do it with a script ... but that means learning the deep innards of the Jira Java API as much as any plugin developer would have to learn.


You will find many examples in this forum. For example:

https://community.atlassian.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&q=scriptrunner+add+user+to+group

https://community.atlassian.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=false&q=scriptrunner+create+group

Vijay Sv May 5, 2021

Thanks, @Peter-Dave Sheehan for the lead...

Yeah, i figured to load a bunch of users using a script but wondering how to append the list of users who are in the DL ? maybe loading it to CSV using python or simple Powershell to get the users list from the DL and appending to the script.

 

Here is my script to add multiple users to a group... 

 

import com.atlassian.jira.component.ComponentAccessor


def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
final String groupName = "GROUPA" // the group you want to add users
def group = ComponentAccessor.groupManager.getGroup(groupName) // user names of the users to add
final List<String> userToAdd = ["USR1", "USR2", "USR3"]


userToAdd.each {
def usertoadd = userManager.getUserByName(it)
if (!usertoadd) {
log.warn("User: $userToAdd doesn't exist")
return

}

if (ComponentAccessor.getGroupManager().getGroupsForUser(usertoadd).contains(group)) {
log.warn("User: $usertoadd.username already in the group: $groupName")
return

}

if(!group) {
log.warn("Group: $groupName doesn't exist")

} else {

userUtil.addUserToGroup(group, usertoadd)
log.warn("User: $usertoadd.username added to the $groupName")

}

}

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2021

If you need to get the list of users from an external source... how you do that depends on the source.

If the data is in LDAP you can connect to LDAP directly from a groovy script

Something like

@Grab(group='org.apache.directory.api', module='api-all', version='2.0.1')
import org.apache.directory.ldap.client.api.*
def ldap = new LdapNetworkConnection(hostName, port)
ldap.bind('userDn', 'userPassword')

Then refer to https://nightlies.apache.org/directory/api/2.0.1/apidocs/ for how to user the various methods.

0 votes
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 29, 2021

Hello @Vijay Sv 

Can you tell us what you are trying to accomplish with this? How do you want to use that Group within JIRA?

Vijay Sv April 29, 2021

To brief, i want to manage a group of contractors who are part of this DL at the project role level and I don't want to disturb the existing LDAP directory where we have permanent Employees and partially contractors. 

I tried adding multiple LDAP directories A & B by adding them to individual groups 1 & 2 as they log in for the first time, users who are part of A will be added to 1 and B will be added 2, perhaps if a contractor is present in both the directories then as they log in the user will be added to the first configured directory then the actual one. 

So i think it cannot be achieved using multiple LDAP directories and i am looking for a way to use scriptrunner/groovy to fetch users from contractors DL to an internal group or any plugin to create an internal group based on the DL.

Suggest an answer

Log in or Sign up to answer