5
votes

For a new project I want to use the new Pipeline feature of Jenkins CI. We have several branches in our Git repository which should be tested in a same way. It should also track and process new branches automatically. Therefore I created a Multibranch Pipeline Job. But I have 2 problems with its configuration:

1) In order to be marked as valid by Jenkins the branch needs a "Jenkinsfile". If this doesn't exist the branch is ignored by Jenkins. Is there any way to mark all branches matching a pattern without it needing to have this file in it?

2) Every branch should have the same Pipeline build script. Unfortunately in the "Build Configuration" section the only option is "By Jenkinsfile". I want to be able to configurate my script locally in the config and it should apply for all branch builds.

Can you help me? Thanks!

Jenkins version 2.10, all plugins are the latest versions.

1
I think the multibranch applies to all branches in the repository. That is you do not need a separate script. I have the same problem but a little worse ... if using multibranch pipeline the build fails if the branch does not have a JenkinsFile.Rob Smyth
This unfortunately would be against the concept of the multibranch pipeline. The Jenkinsfile is considered part of your source code, therefore it has to exist in each branch you want to run. In fact as you noticed without having it in the brach there's no way to tell Jenkins what to do. Anyway it's a good practice to store the configuration file in your repository. Is there something which speaks against this practice? Do you know about the replay feature?Joerg S

1 Answers

0
votes

A multibranch pipeline job will run for all branches in a repository and discover new branches on the crontab schedule you specify in the pipeline config.

If you want different behavior per branch you can do this:

script {
    if( "${env.BRANCH_NAME}" == "master" ) {
        ....
    }
    if( "${env.BRANCH_NAME}" == "integration" ) {
        ....
    }
}