Created
April 23, 2020 19:29
-
-
Save gwsu2008/eadaba556e2700751397030ba0a09705 to your computer and use it in GitHub Desktop.
jenkins-groovy-create-user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.* | |
import hudson.security.* | |
import hudson.tasks.Mailer | |
def userId = 'tester1' | |
def password = 'password!' | |
def email = '[email protected]' | |
def fullName = 'tester1 tester2' | |
def instance = jenkins.model.Jenkins.instance | |
def existingUser = instance.securityRealm.allUsers.find {it.id == userId} | |
if (existingUser == null) { | |
println("Create user ${userId} in jenkins") | |
def user = instance.securityRealm.createAccount(userId, password) | |
user.addProperty(new Mailer.UserProperty(email)); | |
user.setFullName(fullName); | |
} else { | |
println("User ${userId} is already exists") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment