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

'stage' directive with nested 'when' and 'options' directives executes the 'options' block even if the condition is not met

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      My(stripped out) Jenkinsfile looks like this:

      pipeline {
        options {
          gitlabBuilds(builds: ['prepare-build-environment', 'build'])
         }
        stages {
          //stages for preparing the build environment and building 

          stage('Deploy'){
            when {
              anyOf {
                branch 'dev'
                branch 'release'
                branch 'master'

                     }
                  }
            options {
              gitlabBuilds(builds: ['deploy'])
                  }
            steps {
              //my steps
                  }
            post {
              failure {
                updateGitlabCommitStatus name: 'deploy', state: 'failed'
                      }
              success {
                updateGitlabCommitStatus name: 'deploy', state: 'success'

                     }

                   }

              }

          //more stuff

          }
      }
      Since I'm using Multibranch Pipeline, I don't want 'Deploy' stage to happen on feature branches. But GitLab gets notified about 'deploy' stage in all cases, and even if the Jenkins job finishes successfully, pipeline status on GitLab is still "running":

       

      This makes "Merge when pipeline succeeds" useless, since it will never succeed.

        Attachments

          Activity

          Hide
          abayer Andrew Bayer added a comment -

          So the reasoning here is that we want to ensure that options like timeout or retry will apply across the entire stage execution, including, say, input (particularly relevant with timeout) and when. For your use case, you'd want to do something like this:

          steps {
            gitlabBuilds(builds: ['deploy']) {
              // Your actual steps
            }
          }
          

          ...rather than use options.

          Show
          abayer Andrew Bayer added a comment - So the reasoning here is that we want to ensure that options like timeout or retry will apply across the entire stage execution, including, say, input (particularly relevant with timeout ) and when . For your use case, you'd want to do something like this: steps { gitlabBuilds(builds: [ 'deploy' ]) { // Your actual steps } } ...rather than use options .

            People

            • Assignee:
              abayer Andrew Bayer
              Reporter:
              alkopz Alis Adrovic
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: