Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes requested in the code review
Browse files Browse the repository at this point in the history
- Fixed the condition
- Added functionality to allow user to overwrite pre-configured labels

Signed-off-by: Shubham Verma <[email protected]>
VermaSh committed Apr 11, 2018
1 parent c75359f commit 755fe26
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions Jenkins_jobs/UpdateMachineIdentifiers.groovy
Original file line number Diff line number Diff line change
@@ -24,15 +24,20 @@ node {
// We shoulidn't be touching any machine if a project label isn't is passed
error("Neither project label was provied nor overWriteLabels flag was set")
}

if (params.overWriteLabels && labels == null) {
error("No labels supplied for overWriteLabels option")
}

if (params.overWriteLabels) { // Overwrite labels
println "Machine ${machineNames[index]} updated labels: ${nodeHelper.addLabel(machineNames[index], labels[index%labels.length])}"

if (params.overWriteLabels) {

if (labels == null) { // No labels have been supplied so we'll overwrite just with preconfigured labels
String constructedLabels = "${nodeHelper.constructLabels(machineNames[index])}"
println "Machine ${machineNames[index]} updated labels: ${nodeHelper.addLabel(machineNames[index],constructedLabels)}"
} else { // else overwrite with the supplied labels
println "Machine ${machineNames[index]} updated labels: ${nodeHelper.addLabel(machineNames[index], labels[index%labels.length])}"
}

} else if (params.projectLabel.equals("all")
|| nodeHelper.getLabels(machineNames[index]).contains(params.projectLabel)) {

if (labels == null) { // Add preconfigured labels

String constructedLabels = "${params.projectLabel} ${nodeHelper.constructLabels(machineNames[index])}"
@@ -41,6 +46,7 @@ node {
} else { // Append labels
println "Machine ${machineNames[index]} updated labels: ${nodeHelper.appendLabel(machineNames[index], labels[index%labels.length])}"
}

}
}
}
@@ -53,8 +59,8 @@ node {

for (int index = 0; index < machineNames.length; index++) {
println "Pre-update description of ${machineNames[index]}: ${nodeHelper.getDescription(machineNames[index])}"
if (!params.projectLabel.equals("all")
&& nodeHelper.getLabels(machineNames[index]).contains(params.projectLabel)) {
if (params.projectLabel.equals("all")
|| nodeHelper.getLabels(machineNames[index]).contains(params.projectLabel)) {

String description = nodeHelper.getDescription(machineNames[index]);
description += " - ${nodeHelper.getCpuCount(machineNames[index])}CPU";

0 comments on commit 755fe26

Please sign in to comment.