Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-28533

Promoted build does not respect "Restrict where this promotion process can be run" check with empty label

      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:

      /hudson/plugins/promoted_builds/PromotionProcess/process-config.jelly, lines 40-46
        <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:

      hudson.plugins.promoted_builds.PromotionProcess.java, line 118 onwards
          /*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:

      hudson.plugins.promoted_builds.PromotionProcess.java, line 118 onwards
          /*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();
          }
      

          [JENKINS-28533] Promoted build does not respect "Restrict where this promotion process can be run" check with empty label

          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.

          Juan Pablo Santos Rodríguez added a comment - 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.

            Unassigned Unassigned
            juanpablo Juan Pablo Santos Rodríguez
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: