How to use Jenkins multi-configuration for micro-services build process?

248 views Asked by At

To give a background, we have nearly 20 micor-services each of which has its own Jenkinsfile. Although each micro service may be doing some extra steps in their builds, e.g. building extra docker image, but most of these steps are the same across the all micro services, with only difference being the parameters for each step, for example repository path etc.

Now looking at Jenkins' Multi Configuration project it seems perfect to have one of these jobs and apply the build steps to all these projects. However, there are some doubt that I have:

  • Are we able to use Multi Configuration to create Multi Branch jobs for each microservice?
  • Are we able to support extra steps that each micro service may have while the common steps are being generated by Multi Configuration?

To be more clear, let me give you an example.

micro-service-one:
|__ Jenkinsfile
   |___ { step1: maven build
          step2: docker build
          step3: docker build (extra Dockerfile)
        }

micro-service-two:
|__ Jenkinsfile
   |___ { step1: maven build
          step2: docker build
        }

Now what I'm thinking is my Multi Configuration will look like something like this:

Axis:

name: micro-service-one micro-service-two
docker_repo: myrepo.com/micro-service-one myrepo.com/micro-service-two

DSL Script:

multibranchPipelineJob("folder-build/${name}") {
    branchSources {
        git {
            id = 'bitbucket-${name}'
            remote('[email protected]:myproject/${name}.git')
            credentialsId("some_cred_id")
        }
    }
    orphanedItemStrategy {
        discardOldItems {
            daysToKeep(2)
            numToKeep(10)
        }
        defaultOrphanedItemStrategy {
            pruneDeadBranches(true)
            daysToKeepStr("2")
            numToKeepStr("10")
        }
    }
    triggers {
        periodic(5)
    }
}

But I'm not sure how to use the axis variables in the Jenkinsfile for each application? Is it even possible to make Jenkinsfile to be generated by Multi Configuration?

Note: You might ask why do I need this. To answer that, is to reduce the time we spend on modifying or updating these Jenkinsfiles. When a change is needed we need to check out nearly 20 or more repositories and modify one by one as our environment evolving and new features or fixes needed.

0

There are 0 answers