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

stage when result is not respected when used from a library

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Labels:
      None
    • Environment:
      Jenkins ver. 2.46.1 (LTS)
      Pipeline: API / Model 1.1.2
      All other plugins are currently up to date too.
      OS: Windows 7
    • Similar Issues:

      Description

      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?

        Attachments

          Issue Links

            Activity

            Hide
            abayer Andrew Bayer added a comment -

            Yeah, Declarative Pipelines defined in libraries aren't guaranteed to work due to parsing requirements.

            Show
            abayer Andrew Bayer added a comment - Yeah, Declarative Pipelines defined in libraries aren't guaranteed to work due to parsing requirements.
            Hide
            dageissl Daniel Geißler added a comment -

            Andrew Bayer is this limitation documented, did i miss something and are actions taken to change it or should i go without declarative pipeline syntax if i want to use shared libraries?

            I have to manage a whole bunch of jobs that are nearly equal and the shared library configuration is one of the key benefits in the Jenkins Pipeline ecosystem offers. If that is not explicitly supported with declarative pipelines (the current test cases don't seem to have any shared library tests, right?) and anything may break at any time, then declarative pipelines are quiet useless to me and most likely many others too.

            Show
            dageissl Daniel Geißler added a comment - Andrew Bayer is this limitation documented, did i miss something and are actions taken to change it or should i go without declarative pipeline syntax if i want to use shared libraries? I have to manage a whole bunch of jobs that are nearly equal and the shared library configuration is one of the key benefits in the Jenkins Pipeline ecosystem offers. If that is not explicitly supported with declarative pipelines (the current test cases don't seem to have any shared library tests, right?) and anything may break at any time, then declarative pipelines are quiet useless to me and most likely many others too.

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                dageissl Daniel Geißler
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: