Search code examples
jenkinsjenkins-pipelinemultibranch-pipeline

How to use Jenkinsfile from other repo on multibranch


We have a source code of web application in a specific git repo. For that source code, I have created a multi-branch Jenkins project so every branch has it's own Jenkins history

We have an automation pipe where it runs nightly and I need it to run for each of the branches of the web application source code.

The automation pipe is configured as Jenkinsfile and stands in a different repo than the source code of the web application.

Is there a way I can use a Jenkinsfile representing the automation pipeline with the multi-branch project representing the web application source code build?

Or the only option is to move the Jenkins file to the source code of the web application?


Solution

  • Having the Jenkinsfile in the same code repo (and same branches) as the codebase is indeed the best practice and the easiest way to do what you want.

    If you have a particular reason for having it in a different repo, please elaborate. You will need your Jenkinsfile to implement additional logic to identify the various branches, and even more so if you want to have separate jobs for each branch (you'd have to simulate the multibranch essentially). This seems awfully complicated.

    If the reason is to avoid duplicating the Jenkinsfile over multiple branches, then place the logic in a shared pipeline library and have a simple Jenkinsfile referring to it.