Bulk Load Users

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: Read CSV file and put result in a map using Groovy (without using any external libraries) - Stack Overflow
*/
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 has to be on Jira server *************************
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
// 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)

}
}

1 Like