Skip to content

Instantly share code, notes, and snippets.

@asaphe
Created October 10, 2017 11:02
Show Gist options
  • Save asaphe/df2e1e8fc1fb6eeb067c63fb9de770e1 to your computer and use it in GitHub Desktop.
Save asaphe/df2e1e8fc1fb6eeb067c63fb9de770e1 to your computer and use it in GitHub Desktop.
create a user for Jenkins
import jenkins.model.*
import hudson.security.*
def env = System.getenv()
def jenkins = Jenkins.getInstance()
jenkins.setSecurityRealm(new HudsonPrivateSecurityRealm(false))
jenkins.setAuthorizationStrategy(new GlobalMatrixAuthorizationStrategy())
def user = jenkins.getSecurityRealm().createAccount(env.JENKINS_USER, env.JENKINS_PASS)
user.save()
jenkins.getAuthorizationStrategy().add(Jenkins.ADMINISTER, env.JENKINS_USER)
jenkins.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment