Jenkins Docker image building for Different Tenant from same code repository

8/2/2018

I am trying to implement CI/CD pipeline for my Spring Boot micro service deployment. I am planned to use Jenkins and Kubernetes for Making CI/CD pipeline. And I have one SVN code repository for version control.

Nature Of Application

Nature of my application is, one microservice need to deploy for multiple tenant. Actually code is same but database configuration is different for different tenant. And I am managing the configuration using Spring cloud config server.

My Requirement

My requirement is that, when I am committing code into my SVN code repository, then Jenkins need to pull my code, build project (Maven), And need to create Docker Image for multiple tenant. And need to deploy.

Here the thing is that, commit to one code repository need to build multiple docker image from same code repo. Means one code repo - multiple docker image building process. Actually, Dockerfile containing different config for different docker image ie. for different tenant. So here my requirement is that I need to build multiple docker images for different tenant with different configuration added in Dockerfile from one code repo by using Jenkins

My Analysis

I am currently planning to do this by adding multiple Jenkins pipeline job connect to same code repo. And within Jenkins pipeline job, I can add different configuration. Because Image name for different tenant need to keepdifferent and need to push image into Dockerhub.

My Confusion

Here my confusion is that,

  1. Can I add multiple pipeline job from same code repository using Jenkins?
  2. If I can add multiple pipeline job from same code repo, How I can deploy image for every tenant to kubernetes ? Do I need to add jobs for deployment? Or one single job is enough to deploy?
-- Jacob
configuration
jenkins
jenkins-pipeline
kubernetes

1 Answer

8/2/2018

You seem to be going about it a bit wrong.

Since your code is same for all the tenants and only difference is config, you should better create a single docker image and deploy it along with tenant specific configuration when deploying to Kubernetes.

So, your changes in your repository will trigger one Jenkins build and produce one docker image. Then you can have either multiple Jenkins jobs or multiple steps in pipeline which deploy the docker image with tenant specific config to Kubernetes.

If you don't want to heed to above, here are the answers to your questions:

  1. You can create multiple pipelines from same repository in Jenkins. (Select New item > pipeline multiple times).
  2. You can keep a list of tenants and just loop through OR run all deployments in parallel in a single pipeline stage.
-- Amit
Source: StackOverflow