stage when result is not respected when used from a library

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

XMLWordPrintable

      I am extracting the contents of my Jenkinsfile to a common library to reuse it in a number of projects. I have a build step that may be deactivated related on some user input and this is done via when

      This works fine when using the Jenkinsfile but does not as soon as i put it in a library

      Jenkinsfile
      @Library('mybuild') _
      
      buildPipeline {
          name = 'shared build pipeline'
      }
      

      this is the content of the sharedLibrary:

      var/buildPipeline.groovy
      def call(Closure body) {
          // evaluate the body block, and collect configuration into the object
          def config = [:]
          body.resolveStrategy = Closure.DELEGATE_FIRST
          body.delegate = config
      
          body()
      
          // here starts the "real" pipeline
          pipeline {
              agent any
              stages {
                  stage("Two") {
                      when {
                          expression {
                              echo "Should I run?"
                              return false
                          }
                      }
                      steps {
                          echo "World"
                          echo "Heal it"
                      }
                  }
              } // stages
          } // pipeline
      }
      

      expected is:

      [Pipeline] stage
      [Pipeline] { (Two)
      Stage 'Two' skipped due to when conditional
      [Pipeline] echo
      15:36:18 Should I run?
      [Pipeline] }
      [Pipeline] // stage
      

      but i get

      [Pipeline] stage
      [Pipeline] { (Two)
      [Pipeline] echo
      World
      [Pipeline] echo
      Heal it
      [Pipeline] }
      [Pipeline] // stage
      

      anything i am missing?

            Assignee:
            Andrew Bayer
            Reporter:
            Daniel Geißler
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: