I have a lot of projects in different repositories which share the same fundamental CI-workflow, which I can easily express as a Declarative Pipeline:
pipeline {
I am able to use a Shared Library to define a Declarative pipeline that is configurable via a YAML file.
In my repo/project
I define a Jenkinsfile
to call the Shared Library:
@Library('my-shared-library')_
pipelineDefault(); // cannot be named 'pipeline'
and a Jenkinsfile.yaml
to configure the build parameters:
project_name: my_project
debug: true
# you get the idea
Then in my vars/pipelineDefault.groovy
file a very simple Shared Library could look like this:
def call() {
Map pipelineConfig = readYaml(file: "${WORKSPACE}/Jenkinsfile.yaml }")
node {
stage('Build'){
println "Building: ${pipelineConfig.project_name}"
}
}
}
Of course this is a very simplified example, but the dynamic configuration DOES work.
NOTE: this requires the pipeline-utility-steps plugin to read the YAML file