Dicas sobre o Jenkins. Snippets, configurações simples, scripts groovy para autoamizar tarefas etc.
Deletar jobs em massa filtando por nome
import jenkins.model.*
def matchedJobs = Jenkins.instance.items.findAll { job ->
job.name =~ /regex_filter_here/
}
matchedJobs.each { job ->
// println job.name
job.delete()
}
Deletar jobs em massa (TODOS, sem filtro!)
CUIDADO!
import jenkins.model.*
def allJobs = Jenkins.instance.items.findAll()
allJobs.each { job ->
job.delete()
}
Cancelar todos os jobs em execução
import hudson.model.*
def q = Jenkins.instance.queue
q.items.each { q.cancel(it.task) }
Definir um usuário padrão
import jenkins.model.*
import hudson.security.*
println "--> creating admin user"
def adminUsername = System.getenv("JENKINS_USER")
def adminPassword = System.getenv("JENKINS_PASS")
assert adminPassword != null : "No JENKINS_USER env var provided, but required"
assert adminPassword != null : "No JENKINS_PASS env var provided, but required"
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount(adminUsername, adminPassword)
Jenkins.instance.setSecurityRealm(hudsonRealm)
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
strategy.setAllowAnonymousRead(false)
Jenkins.instance.setAuthorizationStrategy(strategy)
Jenkins.instance.save()
Alterar o número de executors
import jenkins.model.*
Jenkins.instance.setNumExecutors(10)
Definir o Crumb Issuer
// imports
import jenkins.model.Jenkins
import hudson.security.csrf.DefaultCrumbIssuer
// get Jenkins instance
Jenkins jenkins = Jenkins.getInstance()
// set default crumb issuer
jenkins.setCrumbIssuer(new DefaultCrumbIssuer(true))
// save current Jenkins state to disk
jenkins.save()
Definir o global Quiet Period
import jenkins.model.Jenkins
Jenkins instance = Jenkins.getInstance()
instance.setQuietPeriod(0)