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

Changing a boolean parameter at build time has no effect on conditional execution of a stage

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • Declarative - 1.2

      Summary:
      Given a Declarative Pipeline with a boolean parameter, which has a default setting of true, one might use this boolean to conditionally execute, or not execute, a particular stage. The syntax I've used to do this is similar to that shown in JENKINS-44298. It appears that changing this boolean at runtime, via the Jenkins UI, has no effect on whether or not the stage gets run.

      Assumptions:
      I'm working under the assumption that, a boolean parameter set up in the parameters

      { ... } section of a pipeline, used in a when { expression { ... }

      } condition written like this:

                  when {
                      expression {
                          return TRUE_OR_FALSE
                      }
                  }
      

      is a valid way of deciding whether or not a stage gets run. Here, if TRUE_OR_FALSE is set to `true`, it'll run. If it's set to false, it won't. Similarly, if it were written like this:

                  when {
                      expression {
                          return !TRUE_OR_FALSE
                      }
                  }
      

      The stage only gets run if TRUE_OR_FALSE is set to `false`.

      I found this approach while working on issue JENKINS-44298.

      Steps to recreate:
      1. Create a new Pipeline job on your Jenkins, and use this as its code:

      pipeline {
          agent any
          parameters {
              // Default value here is true.
              booleanParam(name: 'TRUE_OR_FALSE', defaultValue: true, description: 'This boolean defaults to true!') 
          }
          stages {
              stage('parallel-1') {
                  when {
                      expression {
                          // Given our default value is true, this should 
                          // run if I don't change the parameter from its 
                          // default value of true, to false.
                          return TRUE_OR_FALSE
                      }
                  }
                  steps {
                      echo "MUST BE TRUE"
                  } // end of steps
              } // end of stage
          } // end stages
      }
      

      2. Run this Pipeline by clicking "Build" on the left. The first time you do so, it'll fail anyway, because of a different bug that I'll look for / open separately. Nevermind that for now.

      3. Do a full page refresh in the UI, and the "Build" link has changed to "Build with parameters." Click this link, and leave the defaults. The boolean will be defaulted to True:

      Go ahead and run it this way, and it'll run correctly.

      4. Now, run it again, this time changing the parameter to false:

      5. The stage will still run, as if you had not set the parameter to false.

            jackenliu jianheng liu
            kshultz Karl Shultz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: