사용자 도구

사이트 도구


ci:jenkins:groovy_hook

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
ci:jenkins:groovy_hook [2021/03/30 17:37]
kwon37xi [자동 admin 생성]
ci:jenkins:groovy_hook [2021/06/07 14:25]
kwon37xi [자동 admin 생성]
줄 8: 줄 8:
 ===== 자동 admin 생성 ===== ===== 자동 admin 생성 =====
   * [[https://www.popularowl.com/jenkins/automating-jenkins-install-docker-terraform/|Automating Jenkins install and configuration with Docker and Terraform - Popularowl]] - groovy 스크립트는 너무 오래돼서 안 맞음.   * [[https://www.popularowl.com/jenkins/automating-jenkins-install-docker-terraform/|Automating Jenkins install and configuration with Docker and Terraform - Popularowl]] - groovy 스크립트는 너무 오래돼서 안 맞음.
 +  * [[https://gist.github.com/hayderimran7/50cb1244cc1e856873a4|Jenkins Groovy enable security and create a user in groovy script]]
 +
 +<code groovy>
 +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."
 +}
 +</code>
ci/jenkins/groovy_hook.txt · 마지막으로 수정됨: 2021/06/07 14:25 저자 kwon37xi