Branch specific pipelines in Declarative Pipelines

30 views
Skip to first unread message

Kenneth Brooks

unread,
Jul 7, 2017, 9:34:19 AM7/7/17
to Jenkins Users
As a user, I would like to run different pipelines depending on what branch my commit happens on.

In Declarative Pipelines there is support for doing conditional stages, however, using this conditional logic has 2 issues:
  • You cannot re-order stages based on the branches
  • It makes the pipeline very hard to follow/understand
@AndrewBayer - 
I had opened this jira https://issues.jenkins-ci.org/browse/JENKINS-43576 that showed Environment section (and other things) don't work unless the pipeline{} is at the root of the Jenkinsfile.

The reason I opened this is so that we can load branch specific logic and then based on the result of that we can invoke the declarative pipeline.
We wrote a shared library that allows teams to do this easily.
This allows the internals of each file to be declarative, easy to follow beginning to end and validateable.

Usage:

Using default branch logic

jules_startPipelines(this)

Specifying custom branch to pipeline file mapping

jules_startPipelines(this) {
    pipelineFileMapping = ["develop": "develop-pipeline.groovy",
                           "master": "master-pipeline.groovy",
                           "PR-": "pull-request-pipeline.groovy",
                           "feature": "feature-pipeline.groovy",
                           "supercustom": "super-custom-pipeline.groovy"]
}


But since the environment section doesn't work it is fairly crippled.

What is your advice for achieving branch specific declarative pipelines?

Thanks,
Ken
Reply all
Reply to author
Forward
0 new messages