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

This issue is archived. You can view it, but you can't modify it. Learn more

      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.

            Assignee:
            Andrew Bayer
            Reporter:
            Alis Adrovic
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: