HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Jenkins configuration to support multi-config multi-branch CI

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
multijenkinsbranchconfigconfigurationsupport

Problem

Here are my requirements and I go back-and-forth on how to achieve them:

  • Must build Java spring-boot apps



  • Artifacts must be released to artifactory repository



  • Docker image to be built directly relating to the artifact group/artifactId/version



  • Docker image to be deployed to AWS ACR



  • Container deployment via cloud formation



  • Maintain 2 branches in a git repo: dev and master. dev releases to our development environment and master is for prod (I have tried to explain that this approach made sense when code was app (php) but not when you have a release artifact)



  • All branches off dev must build and test independently but NOT release even snapshots (doesn't apply to master as no one should be working off master)



  • best part dev and prod builds must be done under entirely different AWS credentials and accounts into totally different VPCs



Given these requirements I believe need a multi-configuration pipeline - one for the {prod/master} and {development/dev} arrangement to successfully capture the credential and deployment differences and point them at different branches. What I can't seem to do is get the dev configuration to ALSO build the branches from dev - I have no pattern I can match - the branches don't look like dev-.* - they are mapped directly to Jira tickets.

Can I even do such a thing? I feel like this last part is where my multi-config is breaking down.

Solution

You can use a Jenkinsfile for this. You can add logic with groovy for every condition you've listed above.

You'll want to use a multi-branch pipeline build for sure, and just write in conditions / switches to determine what you want to do based on the current branch. Jenkins provides a global environment variable for all builds: BRANCH_NAME

The job will run on any branch that contains the Jenkinsfile and you can write conditions in for steps if you want to include / exclude certain branches. You can use the when directive for full-step conditions: https://jenkins.io/doc/book/pipeline/syntax/#when

For handling credentials: https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-credentials

Context

StackExchange DevOps Q#1517, answer score: 2

Revisions (0)

No revisions yet.