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

      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.

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

              Created:
              Updated:
              Resolved: