2

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('git@bitbucket.org: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.

xbmono
  • 1,310
  • 1
  • 20
  • 35
  • I don't think multi-configuration will give you what you want - that's generally used for a matrix setup. It sounds like what you're looking for is Shared Libraries. You can encapsulate logic for single steps (like maven build or docker build above), or you can even abstract the entire pipeline declaration out. https://www.jenkins.io/doc/book/pipeline/shared-libraries/ – Craig Kelly Feb 24 '21 at 00:21
  • @CraigKelly Thanks. We are already doing that. So we have shared lib that has all the steps that we need but each repository has different parameter. I am thinking maybe I should define a sort of profile with default parameter values. – xbmono Feb 25 '21 at 01:11
  • 1
    That seems to be pretty standard. For instance, defining a map of defaults in your shared lib somewhere and then deriving the config for a step/var as something like `default_map + env + parameter_map_passed_to_your_var`. Then your individual pipelines can configure at the env or at the step level. – Craig Kelly Feb 25 '21 at 17:17

0 Answers0