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 {
agent any
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
}
stages {
stage('CI') {
steps {
echo 'Do CI'
}
}
stage('QA') {
steps {
echo 'Do QA'
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'
// etc...
}
failure {
echo 'Failure mail'
// etc
}
}
}
I would like to use the same Declarative Pipeline across all my projects and have the ability to change the definition of the Pipeline in just one place and have the changes used in all projects automatically.
Essentially what I would to do in a project;s Jenkinsfile is this:
loadPipelineFromScm 'repository', 'pipeline.groovy'
I can already do this with shared libraries, but then I'm not able to use Declarative Pipeline features anymore.
Is there a way to share a Declarative Pipeline across many repositories?
While the views are left intact using the suggestion from noober01 the declarative pipeline will not function properly. E.g. when clauses will be ignored, since the pipeline element is expected to be top-level, meaning it is parsed as scripted pipeline instead.
See the following issue rejected by the team behind Jenkins: loading external declarative pipelines issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With