We have many, many projects which all have their own Jenkinsfile which simply executes a pipeline defined in our shared library. The pipeline ensures that all projects are built, packaged, and installed in the same exact way.
project-a/Jenkinsfile
library 'the-shared-library'
buildProject name: 'project-a', buildApi: true, ...
the-shared-library/vars/buildProject.groovy
def call(Map config) {
pipeline {
// standard stages go here
}
}
We want to extend this to allow for an additional stage to be executed during the pipeline, for certain projects (e.g. 1 out of the many). I was thinking of doing it as follows, if possible:
- pass a config param which is a Stage, into
buildProject
- in
buildProject.call
, if a custom stage was provided, tack it on to the end of the pipeline, or perhaps between two (known) stages, and run it
Something like this ...
project-a/Jenkinsfile
library 'the-shared-library'
def myCustomStage = ... // not sure how
buildProject name: 'project-a', buildApi: true, ..., customStage: myCustomStage
the-shared-library/vars/buildProject.groovy
def call(Map config) {
def customStage = config.customStage
pipeline {
// standard stages 1 through 3
// if customStage provided, it goes here
// standard stages 5 through 5
}
}
I'm not sure what is a correct solution here.