Configuring Jenkins using ‘conditional steps’ for building multiple services that has different build configuration using single job

Doyle Wilson
3 min readJul 25, 2020

In this post, I will tell you how to set up conditional steps in Jenkins to configure multiple services using single build job. Let’s consider the below use case.

Use case:

Consider the below screenshot, where we have a main repository, with 4 different services.

MS Service 1. MS Service 2, MS Service 3 , uses gradle /maven to build the artifact (.jar or.war). After build, the artifact must be converted to docker image and to be pushed to AWS ECR

Fourth service contain only a shell script and a Docker File. The build must create a docker image with the execution steps mentioned in the DockerFile for the shell script and push the image to the AWS ECR repository.

In Jenkins, setup a single build job that accomplishes the above tasks rather than having multiple build jobs for each service. This is for better extensibility and maintenance.

  1. In Jenkins, under the job, enable choice Parameter option as seen in the screen shot below. Add all the services which needs to be build and pushed to AWS ECR repository.

2. Under Source Code management, give the main repository details as mentioned below.

3. Now in the Build section, look for Conditional steps (multiple) from Add build step drop down.

4. Setup the configuration to build the docker image which does not need gradle and push the image to ECR repository.

5. Add one more conditional steps (multiple) and configure the gradle and execute commands to build the docker image.

Troubleshooting:

While executing the job for conditional steps with gradle, there are chances where it can throw ‘version’ cannot be found. Create a file gradle.properties under the service and define the version of your services.

--

--

Doyle Wilson

Technology Architect | Solution Designer| Java | Microservices | AWS | Terraform | Spring Boot