-
New Feature
-
Resolution: Duplicate
-
Minor
-
None
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:
- walk up the tree of useTemplate
- collect all the libraries and environment blocks from the top down, overriding with lower-level definitions
- execute the stages defined in the lowest-level file, using the inherited stage definition if no closure is supplied
- perhaps support the ability to require that a previous stage has completed (e.g., in the template, require 'Acceptance Tests' before 'Production Deploy'
- duplicates
-
JENKINS-42224 Need ability to create reusable chunks of Declarative Pipeline
- Open