Last active
October 5, 2015 16:18
-
-
Save tckz/2835544 to your computer and use it in GitHub Desktop.
jenkinsでジョブがチェックアウトするブランチを一括設定する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jenkins.model.Jenkins.instance.items.findAll{job -> | |
job.name =~ /^some$/; | |
}.each { job -> | |
def modBranch = {scm -> | |
if (scm?.getType() =~ "GitSCM") { | |
// scm.properties.each{it -> println(it)}; | |
branches = scm.getBranches() | |
if (branches?.size > 0) { | |
println("${job.name}(${scm.scmName})=${branches[0].name}"); | |
//branches[0].setName("b333"); | |
//job.save(); | |
} | |
} | |
} | |
scm = job.getScm(); | |
if (scm?.getType() =~ "MultiSCM") { | |
scm.configuredSCMs.each {scm -> modBranch(scm)} | |
} else { | |
modBranch(scm); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jenkins.model.Jenkins.instance.items.findAll{job -> | |
job.name.endsWith("-some-name"); | |
}.each { job -> | |
if (job.getScm()?.getType() =~ "Git") { | |
branches = job.getScm().getBranches() | |
if (branches?.size > 0) { | |
//println(job.name + "=" + branches[0].name); | |
branches[0].setName("b333"); | |
job.save(); | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
job_names = new HashSet([ | |
"job1", | |
"job2", | |
]); | |
jobs = jenkins.model.Jenkins.instance.items.findAll{job -> | |
job_names.contains(job.name) | |
} | |
jobs.each { job -> | |
branches = job.getScm()?.getBranches() | |
if (branches?.size > 0) { | |
println(job.name); | |
branches[0].setName("master"); | |
job.save(); | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jenkins.model.Jenkins.instance.items.each { job -> | |
if (job.getScm()?.getType() =~ "Git") { | |
branches = job.getScm().getBranches() | |
if (branches?.size > 0 && branches[0].name == "b222") { | |
println(job.name + "=" + branches[0].name); | |
branches[0].setName("b333"); | |
job.save(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment