CircleCI CI/CD Pipeline For MuleSoft Applications

Author: Shyam Kulkarni

CI/CD is a method to frequently deliver apps to customers by introducing automation into the stages of app development. 

  • Let’s consider we have three branches present over GitHub namely: develop, qa, and main.
  • The code present in develop, qa and main branches maps to dev, test, and prod environments of CloudHub respectively.
  • The qa branch is created from the main branch and the develop branch is being created from the qa branch.
  • Now, once the developer pushes the code to the develop branch, the develop pipeline will get triggered, Munits test cases will be executed and the mule application will be deployed to the dev environment of CloudHub.
  • If the code is pushed to the qa branch (i.e through a pull request created from develop to qa and gets merged), qa pipeline will get triggered and the mule application will be deployed to the test environment of CloudHub.
  • Similarly, if the code is pushed to the main branch (i.e through a pull request created from qa to main and gets merged), prod pipeline will get triggered and the mule application will be deployed to the prod environment of CloudHub.
CI/CD Flow Diagram:

Let’s understand how we can do the implementation:

1. As you have your GitHub Repository created, so when you will Log in to Circle CI using the same email ID or your Github Account, your repository will appear in the Projects Tab of Circle CI as follows:

2. Click on Set up Project, you will be asked to enter the branch name from your GitHub repository which contains the script for the pipeline. 

So, before setting up the project, we will work on configuring the Mule Application.

3. First, clone your repository to your local. [Point it towards develop branch]. After cloning, open Anypoint Studio and import that project into your Studio.

4. You can create any sample flow with some basic components, following is what I have created:

Transform Message: payload

%dw 2.0
output application/json

“country”: p(‘secure::location’)

5. Now, let’s configure src/main/resources. Add three properties files namely:, and 

For this POC, I have used only one key to encrypt the property.

6. Now, go to Global Elements and search for Secure Properties Config [If it isn’t available, then go to your Mule Pallet -> Search in Exchange -> Search for Secure Properties -> Add that Module in your Palette] and do the following configuration:

7. Now, go to your pom.xml and add the following under mule-maven-plugin:

<applicationName>${cloudhubApplicationName}</applicationName> <environment>${cloudhubEnvironment}</environment>

<cloudhubPropertyCryptKey>${cloudhubPropertyCryptKey}</cloudhubPropertyCryptKey> </properties>  

It looks like this:

8. Now, open your Mule Project in System Explorer. We need to add two things:

a. Create a folder .circleci -> Inside this folder, add a config.yml file

b. Add settings.xml

It looks like this:

Circle CI Script:
# Java Maven CircleCI 2.0 configuration file
# Check for more details
version: 2
      – image: circleci/openjdk:8-jdk
    working_directory: ~/repo
      cloudhubPropertyEnv: dev
      cloudhubWorkerType: Small
      cloudhubEnvironment: dev
      cloudhubApplicationName: circle-ci-mulesoft-poc-dev
      logLevel: INFO
      – checkout
      – restore_cache: 
         key: mvn-cache-circle-ci-mulesoft-poc-dev
      – run: mvn –settings settings.xml deploy -Denv=dev
-DcloudhubPropertyCryptKey=${cloudhubPropertyCryptKey} -DmuleDeploy      
– save_cache:
            – ~/.m2
          key: mvn-cache-circle-ci-mulesoft-poc-dev
      – image: circleci/openjdk:8-jdk
    working_directory: ~/repo    environment:
      cloudhubPropertyEnv: qa
      cloudhubWorkerType: Small
      cloudhubEnvironment: qa
      cloudhubApplicationName: circle-ci-mulesoft-poc-qa
      – checkout
      – restore_cache:
          key: circle-ci-mulesoft-poc-qa
      – run: mvn –settings settings.xml deploy -Denv=qa -DskipTests -DmuleDeploy
      – image: circleci/openjdk:8-jdk
    working_directory: ~/repo    environment:
      cloudhubPropertyEnv: prod
      cloudhubWorkerType: Small
      cloudhubEnvironment: prod
      MAVEN_OPTS: -Xmx3200m
      cloudhubPassword: ${cloudhubProdPassword}
      cloudhubUser: ${cloudhubProdUser} 
      – checkout
      – restore_cache:
          key: mvn-cache-circle-ci-mulesoft-poc-prod
      – run: mvn –settings settings.xml deploy
-Denv=prod -DskipTests -DmuleDeploy
      – store_artifacts:
          path: targetworkflows:
  version: 2  deploy-develop:
      – deploy-develop:
              only: develop
      – deploy-qa:
              only: qa
      – deploy-prod:
              only: main

You can modify the script depending on what is your application name, branch name, new job to be added, cloudhub env name etc. other parameters as well.

9. After adding the above files, you can commit and push the code to develop the branch.

10. Now, we can move to circleci, and set up the project. Write “develop” branch in the branch section as follows:

11. After this, we need to add environment variables. Click on Project Settings 

Please keep the names as is as they are case sensitive which are being used in circle ci script as well as pom.xml. [Crypt key is your key which you have used earlier to encrypt the values and kept in the properties file]. 

12. Now, you can see the develop branch pipeline being triggered.

You can see the Munits Test cases ran and gave a coverage summary.

You can see the mule application being deployed to CloudHub’s dev environment:

13. Now, create a pull request from develop branch to qa branch and approve and merge it to qa branch. You will see qa pipeline being triggered.

You can see the status of both develop and qa pipelines as Success:

14. Now, create a pull request from qa branch to the main branch and approve and merge it, for it to be deployed to the prod environment. The prod pipeline will get triggered.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.