$JENKINS_HOME/init.groovy
, $JENKINS_HOME/init.groovy.d/
에 넣어둔 .groovy
파일로 Jenkins 가 다 뜬 뒤의 작업을 할 수 있다.$JENKINS_HOME
은 보통은 /var/lib/jenkins
이다./var/log/jenkins/jenkins.log
에 남는다.import jenkins.model.* import hudson.security.* def instance = Jenkins.getInstance() // System.getenv("JENKINS_HOME") - 존재안함 File adminCreatedMarker = new File("/var/lib/jenkins", ".adminCreatedmark") println "mark file path : $adminCreatedMarker" if (adminCreatedMarker.exists()) { println "admin user already exists. skip creating user." } else { def hudsonRealm = new HudsonPrivateSecurityRealm(false) println "admin does not exists. creating admin...." hudsonRealm.createAccount("admin","admin") // username, password instance.setSecurityRealm(hudsonRealm) def strategy = new hudson.security.FullControlOnceLoggedInAuthorizationStrategy() strategy.setAllowAnonymousRead(false) instance.setAuthorizationStrategy(strategy) instance.save() adminCreatedMarker.createNewFile() println "$adminCreatedMarker file created." }