Looking for some assistance on how to accomplish executing different build 
logic based on branch names. In my use case for branches master or PR-? I 
want to execute build + test (basically continuous integration). For 
branches named release-? I want to execute deployment steps. 

Now I know I can do this by using a single Jenkinsfile and putting crazy 
amounts of if statements around each stage. But after a while that just 
becomes overly confusing and hard to follow. What I want to accomplish is 
to actually run separate Jenkinsfile based on the branch name. I believe 
this can be accomplished using the load (or maybe apply from) functionality.

So far I have tried this:

main Jenkinsfile that lives in the repo:

@Library('shared-library@master') _

node('test') {
  stage('Load Build') {
    checkout scm
    load(BRANCH_NAME == 'master' ? 'master.groovy' : 'deploy.groovy')
  }
}

master.groovy that lives in the repo:

#!/usr/bin/env/groovy

podTemplate(label: buildId(), name: buildId, containers: []) {
  node(buildId()) {
    stage('Build') {
      checkout scm
    }
  }
}

This somewhat works but I don't know if it is the best way to accomplish 
this.

First, issue is that in Blue Ocean it collapses everything to one stage, 
that stage being 'Load Build'.

Second, I have to allocate two nodes and checkout the source code twice. 
The first node allocation is in the main Jenkinsfile. That is required as I 
need to checkout the source code due to the fact that master.groovy lives 
in the repository in question. The second node allocation and code checkout 
is in what is the main pipeline (master.groovy). 

My hope is that I could load this file (master.groovy or deploy.groovy) 
from the shared library, as well as pass parameters to it. 

Any assistance on how to best accomplish this would be appreciated.

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/1996284a-743e-450c-8afb-7730d4d2b662%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to