문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 | ||
ci:jenkins:groovy_hook [2020/09/03 15:30] kwon37xi 만듦 |
ci:jenkins:groovy_hook [2021/06/07 14:25] (현재) kwon37xi [자동 admin 생성] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Jenkins Groovy Hook ====== | ====== Jenkins Groovy Hook ====== | ||
* [[https:// | * [[https:// | ||
- | * '' | + | * '' |
+ | * '' | ||
+ | * 출력은 ''/ | ||
+ | * see [[ci: | ||
+ | ===== 자동 admin 생성 ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | <code groovy> | ||
+ | import jenkins.model.* | ||
+ | import hudson.security.* | ||
+ | |||
+ | def instance = Jenkins.getInstance() | ||
+ | // System.getenv(" | ||
+ | File adminCreatedMarker = new File("/ | ||
+ | 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(" | ||
+ | instance.setSecurityRealm(hudsonRealm) | ||
+ | |||
+ | def strategy = new hudson.security.FullControlOnceLoggedInAuthorizationStrategy() | ||
+ | strategy.setAllowAnonymousRead(false) | ||
+ | instance.setAuthorizationStrategy(strategy) | ||
+ | |||
+ | instance.save() | ||
+ | adminCreatedMarker.createNewFile() | ||
+ | println " | ||
+ | } | ||
+ | </ |