Skip to content

Instantly share code, notes, and snippets.

@tckz
Last active October 5, 2015 16:18
Show Gist options
  • Save tckz/2835544 to your computer and use it in GitHub Desktop.
Save tckz/2835544 to your computer and use it in GitHub Desktop.
jenkinsでジョブがチェックアウトするブランチを一括設定する
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);
}
}
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();
}
}
}
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();
}
}
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