jenkins/docker/init.groovy.d/basic-security.groovy

21 lines
695 B
Groovy
Raw Permalink Normal View History

2024-11-12 07:49:27 +00:00
import jenkins.model.*
import hudson.security.*
def instance = Jenkins.getInstance()
// ユーザー名とパスワードを設定
def adminUsername = System.getenv("JENKINS_USER") ?: "admin"
def adminPassword = System.getenv("JENKINS_PASS") ?: "password"
// セキュリティ設定を行い、管理者アカウントを作成
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount(adminUsername, adminPassword)
instance.setSecurityRealm(hudsonRealm)
// 全ユーザーにアクセス権を付与
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
strategy.setAllowAnonymousRead(false)
instance.setAuthorizationStrategy(strategy)
instance.save()