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

Add support for defining Declarative pipelines in shared libraries

    • Icon: New Feature New Feature
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • jenkins 2.76 and 2.60.3, pipeline model definition plugin 1.1.9

      I have project https://github.com/patope/jenkins-pipeline-test having two branches: master and direct. On 'direct' pipeline is defined in Jenkinsfile file and on master Jenkinsfile uses shared pipeline.

      Shared pipeline is defined in https://github.com/patope/jenkins-pipeline-test-shared

      On branch 'direct' stage 'Build 2' is skipped correctly.

      On branch 'master' (using shared pipeline) stage 'Build 2' is executed. 

       

      pipeline {
        agent any
        stages {
          stage('Build 1') {
            when { expression { true } }
            steps {
              echo('1')
            }
          }
          stage('Build 2') {
            when { expression { false } }
            steps {
              echo('2')
            }
          }
          stage('Build 3') {
            when { expression { true } }
            steps {
              echo('3')
            }
          }
        }
      }
      

       

          [JENKINS-46547] Add support for defining Declarative pipelines in shared libraries

          Tomi Pakarinen created issue -
          Andrew Bayer made changes -
          Link New: This issue is duplicated by JENKINS-46558 [ JENKINS-46558 ]
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Andrew Bayer made changes -
          Summary Original: Declarative pipeline 'when' conditions do not work when using shared pipeline New: Add support for defining Declarative pipelines in shared libraries
          Andrew Bayer made changes -
          Issue Type Original: Bug [ 1 ] New: New Feature [ 2 ]
          Andrew Bayer made changes -
          Link New: This issue is blocking JENKINS-42730 [ JENKINS-42730 ]
          Andrew Bayer made changes -
          Link New: This issue relates to JENKINS-42224 [ JENKINS-42224 ]

          Andrew Bayer added a comment -

          So as of now, this isn't expected to work (but isn't well documented that it won't) - pipeline blocks can only be defined in the main Pipeline itself, not in a shared library.

          But...I'm starting some experiments here. Here's what I'm aiming at right now:

          • You can only call pipeline inside the call method on a class in vars in a shared library. I'm still working out how to be sure it's only in a shared library - I've got it to only look in call methods already.
          • Right now, only the first pipeline invocation inside a call method is used - this'll probably change down the road, though, so that you can do conditional selection of a pipeline.
          • This isn't covering any other use cases but entire pipeline blocks - JENKINS-42224 is where I'll hopefully address things like defining a stage in a shared library.

          Andrew Bayer added a comment - So as of now, this isn't expected to work (but isn't well documented that it won't) - pipeline blocks can only be defined in the main Pipeline itself, not in a shared library. But...I'm starting some experiments here. Here's what I'm aiming at right now: You can only call pipeline inside the call method on a class in vars in a shared library. I'm still working out how to be sure it's only in a shared library - I've got it to only look in call methods already. Right now, only the first pipeline invocation inside a call method is used - this'll probably change down the road, though, so that you can do conditional selection of a pipeline . This isn't covering any other use cases but entire pipeline blocks - JENKINS-42224 is where I'll hopefully address things like defining a stage in a shared library.

          Andrew Bayer added a comment -

          Andrew Bayer added a comment - Very preliminary PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/193
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #193 (Web Link)" [ 17668 ]

            abayer Andrew Bayer
            patope Tomi Pakarinen
            Votes:
            2 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: