jenkins Jenkins Groovy Scripting Create default user

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

  1. Create groovy file by path $JENKINS_HOME/init.groovy.d/basic-security.groovy

In Ubuntu 16 Jenkins home directory places in /var/lib/jenkins

  1. Place in file next code
#!groovy

import jenkins.model.*
import hudson.security.*

def instance = Jenkins.getInstance()

def hudsonRealm = new HudsonPrivateSecurityRealm(false)

hudsonRealm.createAccount("admin_name","admin_password")
instance.setSecurityRealm(hudsonRealm)
instance.save()
  1. Restart Jenkins service
  2. After Jenkins starts you need to remove $JENKINS_HOME/init.groovy.d/basic-security.groovy file


Got any jenkins Question?