Skip to content

Instantly share code, notes, and snippets.

@vikrantyadav11
Created May 2, 2021 18:18
Show Gist options
  • Select an option

  • Save vikrantyadav11/dadeffe7034653d7f1f05ddb8129a13c to your computer and use it in GitHub Desktop.

Select an option

Save vikrantyadav11/dadeffe7034653d7f1f05ddb8129a13c to your computer and use it in GitHub Desktop.
Create new jira user in JIRA Internal Directory
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
// the username of the new user - needs to be lowercase and unique - required
final String userName = "vikrant_kumar"
// The password for the new user - if empty a random password will be generated
final String password = "password"
// The email address for the new user - required
final String emailAddress = "[email protected]"
// The display name for the new user - required
final String displayName = "Vikrant Kumar"
//This display the directory
def directoryId = 1L
// notifications are sent by default, set to false to not send a notification
final boolean sendNotification = false
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def userService = ComponentAccessor.getComponent(UserService)
def newCreateRequest = UserService.CreateUserRequest
.withUserDetails(loggedInUser, userName, password, emailAddress, displayName)
.inDirectory(directoryId)
.sendNotification(sendNotification)
def createValidationResult = userService.validateCreateUser(newCreateRequest)
assert createValidationResult.isValid() : createValidationResult.errorCollection
userService.createUser(createValidationResult)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment