So I'm trying to make a Multibranch Pipeline for a few different projects.
These are the basic requirements:
So these requirements are pretty straightforward.
But there's a fourth requirement. What I'm trying to figure out is if I can have a repo that can hold all of my jenkinsfiles and then build all the branches of another repo. Is this possible? All other answers seem to point to deprecated solutions, such as a freestyle Multibranch project.
Is it possible to build a Multibranch Pipeline with a jenkinsfile from another repo?
Short answer: No, it's not, since each Job in Multibranch Pipeline always references the Jenkinsfile from the same branch (hence, from the same repo) it is configured to monitor. And the branches which do not contain Jenkinsfile are not indexed.
Extended answer: In order to achieve more or less what you're asking for, I would do the following:
Jenkinsfiles
(per-branch, per-client, per-env... whatever).
Each Jenkinsfile
will describe the stages you want to execute in each particular case. Use Scripted Pipeline syntax.Jenkinfile
to your product repo where you: checkout the dedicated repo with your custom pipelines, load a pipeline and execute it.Example
[email protected]:your-org/custom-pipelines.git/Jenkinsfile-dev
// Jenkinsfile-dev
def stages() {
stage ("Checkout") {
checkout scm
}
stage ("Build") {
}
stage ("Test") {
}
}
return this
[email protected]:your-org/product-repo.git/Jenkinsfile
// Jenkinsfile
node ("ubuntu") {
// Checkout custom Jenkinsfiles
stage ("Checkout pipelines") {
git url: "[email protected]:your-org/custom-pipelines.git",
branch: "master",
credentialsId: "github-ssh"
}
load ("Jenkinsfile-${env.BRANCH_NAME}").stages()
}
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