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

Ability to import/inherit pipeline stages

    Details

    • Similar Issues:

      Description

      I have several Java projects that have some essentially identical stages--e.g., the Build stage increments the version number, does some sanity checks, and performs a Maven build with unit tests. All of the differences between these projects can be isolated in the environment or build parameters (e.g. PROJECT_NAME="foo").

      It would be helpful to be able to inherit or compose pipelines in such a way that I could do something like this (just as a conceptual example):

      PipelineTemplate.groovy
      pipeline(template: true) {
        agent any
      
        environment {
          NEW_VERSION = computeVersion()
        }
      
        stages {
          stage('Build') {
            // Maven stuff
          }
      
          stage('Staging Deploy') {
            sh 'cf push $APP_NAME ...'
          }
      
          stage('Production Deploy) { ... }
        }
      }
      
      project/Jenkinsfile
      pipeline(useTemplate: 'PipelineTemplate') {
        environment {
          APP_NAME = 'foo'
        }
      
        stages {
          stage('Build') // no closure
          stage('Staging Deploy')
          stage('Staging Tests') {
            // stuff
          }
          stage('Production Deploy')
        }
      }
      

      The general logic being something like:

      1. walk up the tree of useTemplate
      2. collect all the libraries and environment blocks from the top down, overriding with lower-level definitions
      3. execute the stages defined in the lowest-level file, using the inherited stage definition if no closure is supplied
      4. perhaps support the ability to require that a previous stage has completed (e.g., in the template, require 'Acceptance Tests' before 'Production Deploy'

        Attachments

          Issue Links

            Activity

            There are no comments yet on this issue.

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                chrylis Christopher Smith
              • Votes:
                1 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: