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

Shared Library should be allowed to declare reusable stages

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Currently, we have a lot of reusable steps we use in our Jenkinsfiles like so:

      pipeline {
        stages {
          stage('Build') {
            steps {
              reusableBuild()
            }
          }
          stage('Test') {
            steps {
              reusableTest()
            }
          }
        } 
      }

      I feel it is very repetitive to always replicate the stage definition - the way I look at this, these should be reusable as well. A pipeline would then simply consist of reusable, composable stages:

      pipeline {
        stages {
          reusableBuild()
          reusableTest()
          stage 'Something individual' {
            steps {
              echo 'only for this project'
            }
          }
        } 
      }

      Maybe this is already possible, but at the moment I have no idea how to define reusable stages in a shared library - any hint would be very much appreciated. I would also be willing to provide a PR, if only I had an idea which code to touch

        Attachments

          Issue Links

            Activity

            Hide
            franknarf888 Frank Gen added a comment -

            Hello,

            This fix is marked as "Fixed but Unreleased", can someone add a pointer to the PR implementing this? Or any documentation?

            Thanks

            • Frank
            Show
            franknarf888 Frank Gen added a comment - Hello, This fix is marked as "Fixed but Unreleased", can someone add a pointer to the PR implementing this? Or any documentation? Thanks Frank
            Hide
            colmose Colm O'Shea added a comment -

            Would also love to see if there is docs or something for this?

            Show
            colmose Colm O'Shea added a comment - Would also love to see if there is docs or something for this?
            Hide
            cjharmath CJ Harmath added a comment - - edited

            I would like this as well.

            Use case:

            share build stages across similar projects, to keep things DRY and have a central shared library defining the various build stages per project types.

            i.e.: I might have many many microservices all using the same 1) package restore 2) lint 3) build 4) run unit tests  stages with only parameter differences and it would be awesome if app devs can just include a single line with the necessary parameters to call these 4 steps.

             

            so instead of

             

            stages {
                stage('restore') {
                 steps {
                  echo 'package restore'      
                  restore()     
                 }
            
              }
            stage('build') {
               steps {
                 echo 'building'
                 build()
                }
            
              }
            stage('test') {
                steps {
                  echo 'testing'
                  test()
                 }
            
              }
             }
            

             

            you could do this:

             

            stages {   
               sharedMicroserviceStages()
            }
            

             

             

            Show
            cjharmath CJ Harmath added a comment - - edited I would like this as well. Use case: share build stages across similar projects, to keep things DRY and have a central shared library defining the various build stages per project types. i.e.: I might have many many microservices all using the same 1) package restore 2) lint 3) build 4) run unit tests  stages with only parameter differences and it would be awesome if app devs can just include a single line with the necessary parameters to call these 4 steps.   so instead of   stages {    stage( 'restore' ) {     steps { echo ' package restore'      restore()     }   } stage( 'build' ) {   steps { echo 'building' build() }   } stage( 'test' ) {    steps { echo 'testing'      test() }  } }   you could do this:   stages {       sharedMicroserviceStages() }    
            Hide
            cjharmath CJ Harmath added a comment -

            Okay, so I just re-read the docs and as I understand what I should be doing is to just put the entire pipeline into my shared library.

            https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines

            This kind of makes me wonder if we allow defining entire pipeline, why not allow stages as well ?

            But I guess I am already happy with this as I only need to maintain one pipeline per app type.

            Show
            cjharmath CJ Harmath added a comment - Okay, so I just re-read the docs and as I understand what I should be doing is to just put the entire pipeline into my shared library. https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines This kind of makes me wonder if we allow defining entire pipeline, why not allow stages as well ? But I guess I am already happy with this as I only need to maintain one pipeline per app type.
            Hide
            dalvizu Dan Alvizu added a comment -

            For anyone else who runs into this: Andrew closed this as 'FIxed but unreleased' but with a resolution of 'Duplicate'.

             

            The duplicate issue is JENKINS-49135 and track there

            Show
            dalvizu Dan Alvizu added a comment - For anyone else who runs into this: Andrew closed this as 'FIxed but unreleased' but with a resolution of 'Duplicate'.   The duplicate issue is  JENKINS-49135 and track there

              People

              • Assignee:
                Unassigned
                Reporter:
                tobilarscheid Tobias Larscheid
              • Votes:
                22 Vote for this issue
                Watchers:
                45 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: