Reputation: 31
I am trying to build a Jenkins Declarative pipeline with a Jenkinsfile. The Jenkinsfile would be present on the repo of the project.
The Jenkinsfile would be something like the following:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building..'
}
}
stage('Test') {
steps {
echo 'Testing..'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
} }
However, I would like to enforce some stages in Jenkins regardless of the file. So as an example the pipeline would run Build -> Test -> Deploy stages from the file and an additional stage predefined on Jenkins like if it was a scripted pipeline.
Do you know if this is possible? How can I do it?
Upvotes: 2
Views: 1189
Reputation: 318
Maybe you can try out Jenkins Templating Engine. It gives you comprehensive Jenkins pipeline governance and templating capability.
Upvotes: 1
Reputation: 3095
You could use a shared library to reuse code. It won't be as smooth as you probably liked, but you might use global variables and/or custom steps to encapsulate common functionality.
This would require some glue code (@Library()
, script { }
etc.), but this approach is very explicit and powerful - you can use library in any place in your pipeline.
Upvotes: 1