Skip to content

Instantly share code, notes, and snippets.

@vikrantyadav11
Last active November 1, 2023 16:31
Show Gist options
  • Select an option

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

Select an option

Save vikrantyadav11/8fee8a9b1e245aa2b085452c1f92778a to your computer and use it in GitHub Desktop.
New JIRA User in JIRA Internal Directory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.user.UserEventType
import com.atlassian.jira.exception.CreateException
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.UserDetails
def uu = ComponentAccessor.userUtil
// START config
def directoryId = 1L
def password = "dummy-password-for-all-users"
def fullname = "joeh.deo"
def usernamesWithMail = [ // "username": "mail-address"
"john.doe" : "john.doe@example.com",
"max.mustermann": "mm@example.com"
]
// END config
// START code
def successCount = 0
def failCount = 0
log.warn("creating ${usernamesWithMail.size()} users...")
usernamesWithMail.each { username, mail ->
try {
def userDetails = new UserDetails(fullname, username)
.withDirectory(directoryId)
.withPassword(password)
.withEmail(mail)
def user = uu.createUser(userDetails, false, UserEventType.USER_CREATED, [] as Set)
successCount++
log.warn("created user $user.name with mail $user.emailAddress")
} catch (CreateException e) {
log.warn("could not create user $username with mail $mail: $e.message")
failCount++
} catch (e) {
log.error("error creating user $username with mail $mail", e)
failCount++
}
}
def res = "created $successCount users, $failCount failed"
log.warn("$res")
"$res. see Logs tab"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment