Is there a way to create two different pipelines for one branch repository? Currently I have one Jenkinsfile and it is manually built using the Jenkins GUI. I want to create a second Jenkinsfile that will also be built trough the Jenkins GUI but I do not know how to have both of these pipelines in the same branch and build whichever I want.
Ultimately, a branch's Jenkinsfile describes the Pipeline for that branch. Fundamentally, there can be only one Jenkinsfile, and therefore one Pipeline, per Git repository branch.
Step 1: Open Jenkins home page ( http://localhost:8080 in local) & click on New Item from the left side menu. Step 2: Enter Jenkins job name & choose the style as multibranch pipeline and click OK. Step 3: In the configure page, we need to configure only one thing – The Git Repo source.
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
You can use declarative pipeline to do this. Create two files in your repo say firstPipeline.groovy and secondPipeline.groovy as follows and configure your jenkins job with the one which you want to build:
firstPipeline.groovy:
pipeline {
stages {
stage('stage 1') {
steps {
script{
//do your things of first pipeline stage
}
}
}
stage('stage 2') {
steps {
script{
//do your things of first pipeline stage
}
}
}
}
}
secondPipeline.groovy:
pipeline {
stages {
stage('stage 1') {
steps {
script{
//do your things of second pipeline stage
}
}
}
stage('stage 2') {
steps {
script{
//do your things of second pipeline stage
}
}
}
}
}
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