I have a standardized declarative Jenkinsfile used in many projects. I have moved the entire pipeline into a library, so my Jenkinsfile looks like this:
@Library('default_jenkins_libs') _
default_pipeline();
The library (var/default_pipeline.groovy):
def call() {
pipeline {
node { <snip> }
stages {
stage('Lint and style') {
steps {
//stuff
}
}
//etc...
stage('Post-build') {
steps {
PostBuildStep();
}
}
}
}
def PostBuildStep() {
echo 'Running default post-build step';
}
I want to be able to add a definition to the actual pipeline code in the Jenkinsfile, like so:
@Library('default_jenkins_libs') _
def PostBuildStep() {
echo 'Running customized post-build step'
//do custom stuff
}
default_pipeline();
I have not been able to figure out how to do this. I've suspect this may be doable by the library calling the object represented by the Jenkinsfile and calling its "PostBuildStep()", maybe like 'parent.PostBuildStep()" but I do not have the class structure/naming reference.
Any suggestions? Bottom line is, I want a standardized pipeline that is changeable en masse via a library change, but still give some control to jobs that use it.
TIA