Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,457,608
Community Members
 
Community Events
176
Community Groups

Bulk Upload Users into Jira

Bulk uploading users into Jira can be confusing. I found a few scripts and put them together into one script. This does require ScriptRunner and access to your server's folders.

I started out using the Script Editor for the code and then used Console to execute the script. The Editor allows me to save the file for later use.

The users were loaded into a CSV with User ID, Password, Email Address and Display Name. We use single sign on so the password value was empty.

I uploaded the file to our server so the script could access it.

Hope this helps someone in the future.

 

/*
CSV Format
user ID, Email, full name


CSV parsing code copied from: https://stackoverflow.com/questions/49675423/read-csv-file-and-put-result-in-a-map-using-groovy-without-using-any-external-l
*/
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.user.UserService.CreateUserRequest
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor


File file = new File("//homedev/isdev//Persons.csv")

def csvMapList = []

file.eachLine { line ->
def columns = line.split(",")

// the username of the new user - needs to be lowercase and unique - required
String userName = columns[0]
// The password for the new user - if empty a random password will be generated
String password = ""
// The email address for the new user - required
String emailAddress = columns[1]
// The display name for the new user - required
String displayName = columns[2]

// notifications are sent by default, set to false to not send a notification
boolean sendNotification = false
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userService = ComponentAccessor.getComponent(UserService)
// see if this user already has an account
def user = ComponentAccessor.userManager.getUserByName(userName)
// new user
if (user == null) {
log.warn("add user "+columns[0]+ " "+ columns[1]+ " "+ columns[2])

def newCreateRequest = UserService.CreateUserRequest.withUserDetails(loggedInUser, userName, password, emailAddress, displayName)
.sendNotification(sendNotification)

def createValidationResult = userService.validateCreateUser(newCreateRequest)
assert createValidationResult.valid : createValidationResult.errorCollection

userService.createUser(createValidationResult)

}
}

2 comments

Taranjeet Singh Community Leader Feb 03, 2022

@Jon Kocen Thanks for sharing this useful method of bulk creating/uploading users in Jira!

This will definitely be useful for users using ScriptRunner in their Jira instances.

@Jon Kocen 

Will this work for Service Management users?

It should work for Service Management users since the underlying user context is probably the same.

Like Todd Winton likes this

Comment

Log in or Sign up to comment