Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multibranch Pipeline vs Pipeline job

Now that the Multibranch Pipeline job type has matured, is there any reason to use the simple Pipeline job type any longer? Even if you only have one branch today, it's probably wise to account for the possibility of multiple branches in the future, so what would the motivation be to use the Pipeline job type for your Jenkins Pipeline vs. always using the Multibranch Pipeline job type, assuming you are storing your Jenkinsfile in SCM? Is there feature parity between the two job types now?

like image 431
Neil Avatar asked Jun 14 '16 15:06

Neil


2 Answers

In my experience with multibranch pipelines, the ONLY downside is that you can't see the last success/failure/duration columns on the Jenkins main page. They just show "NA" on the Jenkins front page since it's technically a 'folder' of sub-jobs.

Other than that I can't think of any other "cons" to using multibranch.

I disagree with the other answer.... that case was that multibranch sends changes for "any" branch. That's not necessarily true. If a Jenkinsfile exists on a random feature branch, but that branch is not defined in the pipeline then you can just not do anything with it using typical if/else conditionals.

For example:

node {   checkout scm   def workspace = pwd()    if (env.BRANCH_NAME == 'master') {     stage ('Some Stage 1 for master') {       sh 'do something'     }     stage ('Another Stage for Master') {       sh 'do something else here'     }   }    else if (env.BRANCH_NAME == 'stage') {     stage ('Some stage branch step') {       sh 'do something'     }     stage ('Deploy to stage target') {       sh 'do something else'     }   }    else {     sh 'echo "Branch not applicable to Jenkins... do nothing"'   } } 
like image 190
emmdee Avatar answered Sep 19 '22 00:09

emmdee


Multibranch Pipeline works well if your Jenkins job deals with a single git repository. On the other hand, the pipeline job can be repository-neutral and branch-neutral and very flexible when working with multiple git repositories with a single Jenkins job.

For example, assume you have artifact-1 from repo-1, artifact-2 from repo-2, and integration tests from repo-3. And artifact-2 depends on artifact-1. A Jenkins job has to build artifact-1, then build artifact-2, and finally run integration tests from repo-3. And assume your code change goes to a feature-1 branch of repo-1 and feature-1 branch for new tests in repo-3. In this case, the Jenkins job builds feature-1 for artifact-1, then uses 'dev' branch as default from repo-2 (if feature-1 is not detected in repo-2), and runs 'feature-1' from repo-3 for new integration tests. As you can see, the job works well with three git repositories. A repo-neutral/branch-neutral pipeline job is ideal in this setting.

like image 42
nick w. Avatar answered Sep 22 '22 00:09

nick w.