https://dev.to/jalogut/centralise-jenkins-pipelines-configuration-using-shared-libraries
Is what I just found. I will give this a try.
On Tuesday, May 1, 2018 at 11:07:34 AM UTC-7, Matthew Ceroni wrote:
>
> 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/e5c14f97-1dcd-403f-b095-403062d28ca0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.