-
Bug
-
Resolution: Unresolved
-
Major
-
None
promoted builds plugin offers a "Restrict where this promotion process can be run" check, which in turn enables an input text label, which is accompanied by a "If not set, the label of the promoted build will be used" text.
So, every time you set the check to restrict where to run the promotion, with an empty label, the promoted job should run in the same node of the label. But if you go to the job's configuration screen, leave it untouched and save it, this parameter is lost and the promotion executes on any given node.
As it turns out, the check to restrict where to run the promotion is enabled or not depending on the value of the label's input text:
<f:optionalBlock name="hasAssignedLabel" title="${%Restrict where this promotion process can be run}" checked="${instance.assignedLabelString!=null}" inline="true"> <f:entry title="${%Label Expression}" description="If not set, the label of the promoted build will be used."> <f:textbox autoCompleteDelimChar=" " name="assignedLabelString" value="${instance.assignedLabelString}" autoCompleteField="assignedLabelString"/> </f:entry> </f:optionalBlock>
on the other hand, every time you save the promotion, the value of the node label is saved depending on wheter you've selected the check box or not:
/*package*/ void configure(StaplerRequest req, JSONObject c) throws Descriptor.FormException, IOException { // apply configuration conditions.rebuild(req,c.optJSONObject("conditions"), PromotionCondition.all()); buildSteps = (List)Descriptor.newInstancesFromHeteroList( req, c, "buildStep", (List) PromotionProcess.getAll()); icon = c.getString("icon"); if (c.optBoolean("hasAssignedLabel")) { assignedLabel = Util.fixEmptyAndTrim(c.optString("assignedLabelString")); } else { assignedLabel = null; } save(); }
The problems lies inside the if(..) statement, specifically on Util.fixEmptyAndTrim(c.optString("assignedLabelString"));, which transforms empty Strings to null, efectively disabling the input check on next save.
Suggested fix:
/*package*/ void configure(StaplerRequest req, JSONObject c) throws Descriptor.FormException, IOException { // apply configuration conditions.rebuild(req,c.optJSONObject("conditions"), PromotionCondition.all()); buildSteps = (List)Descriptor.newInstancesFromHeteroList( req, c, "buildStep", (List) PromotionProcess.getAll()); icon = c.getString("icon"); if (c.optBoolean("hasAssignedLabel")) { assignedLabel = c.optString("assignedLabelString") != null ? c.optString("assignedLabelString") : ""; } else { assignedLabel = null; } save(); }
Suggested solution still needs some rework on /hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly, as the empty string on the input field is displayed as "". Perhaps would be easier to track the checkbox usage indepently of the input field? Anyway, we managed to bypass our job requirement of executing the promotion on the same node as the job build, so we are moving away from this issue.