Implementing CI/CD in mule using Jenkins

Priyanka Paul
4 min readSep 8, 2020

Introduction:

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Continuous Delivery (CD) is the ability to get changes of all types including new features, configuration changes, bug fixes and experiments into production. Jenkin is a highly used automation tool to implement the CI/CD.

Core steps to implement Jenkins CI/CD:

1. Mulesoft Anypoint CloudHub set up

2. GitHub configuration

3. Jenkins configuration

4. Maven-plugin setup in Mulesoft Project

Mulesoft Anypoint CloudHub set up:

Enlist the below information from mulesoft Anypoint account

  1. Navigate to https://anypoint.mulesoft.com
  2. Check your Anypoint credentials ( username and password)
  3. Deployment environment ( example -Development, Sandbox, Production, Test)

GitHub configuration:

Enlist the below information from Github account

  1. Navigate to your GitHub account https://github.com
  2. Check your GitHub credentials ( username and password)
  3. Git repository URL Where you want to implement CI/CD (example-https://github.com/apiseroPriyanka/apisero-demo-cicd-api.git)

Jenkins configuration:

Steps to configure Jenkins to automate the entire CI/CD process

Step1: Download the Jenkins jar (https://www.jenkins.io/download/)

Step2: Unzip and execute the exe file and host the application. (By default it will use 8080 port, you can also customize the port (example — 8082)

Step3: Navigate to http://localhost:8082/ and login first time as admin using admin username and password.

Step4: Create global credentials

  • Jenkins>Credentials>System>Global credentials (unrestricted)>add credentials > save
  • Create both git and Anypoint global credentials using a unique ID as “git.credentials” and “anypoint. credentials

Step5: Creating a Jenkins pipeline using global credentials.

  • Jenkins> new item> enter new item name(exm-pipeline1) > select pipeline > save
  • Jenkins>pipeline> build trigger tab> select Poll SCM> set schedule value as > * * * * * (given expression is one minute but you can customize this according to your requirement)
  • Jenkins>pipeline1>pipeline tab> select pipeline script from SCM> select SCM value as “Git”> provide git repository URL and select previously configured global git credential and branch “master” or customize the branch name where you want to implement CI/CD.
  • Add additional behaviour> select advance clone behaviour >shallow clone> set shallow clone depth value as “1” ( For every first commit CI/CD will be triggered)> save
  • Done your Jenkins pipeline is created.

Maven-plugin setup in Mulesoft Project:

The last step is creating a Jenkinsfile and adding the Mule Maven Plugin configuration to the mule pom.xml file.

  1. Create a new file named “Jenkinsfile” under mule root project directory.

2. Configure this file with the below script

pipeline {

agent any

stages {

stage(‘Build Application’) {

steps {

bat ‘mvn clean install’

}

}

stage(‘Test’) {

steps {

echo ‘Application in Testing Phase…’

bat ‘mvn test’

}

}

stage(‘Deploy CloudHub’) {

environment {

ANYPOINT_CREDENTIALS = credentials(‘anypointPlatform’)

}

steps {

echo ‘Deploying mule project due to the latest code commit…’

echo ‘Deploying to the configured environment….’

bat ‘mvn package deploy -DmuleDeploy -Dusername=${ANYPOINT_CREDENTIALS_USR} -Dpassword=${ANYPOINT_CREDENTIALS_PSW} -DworkerType=Micro -Dworkers=1 -Dregion=us-west-2’

}

}

}

}

3. Configure the pom.xml with the below maven plugin under <build><plugins> tag

<plugin>

<groupId>org.mule.tools.maven</groupId>

<artifactId>mule-maven-plugin</artifactId>

<plugin>

<groupId>org.mule.tools.maven</groupId>

<artifactId>mule-maven-plugin</artifactId>

<version>${mule.maven.plugin.version}</version>

<extensions>true</extensions>

<configuration>

<cloudHubDeployment>

<uri>https://anypoint.mulesoft.com/</uri>

<muleVersion>${app.runtime}</muleVersion>

<username>${username}</username>

<password>${password}</password>

<applicationName>${project.artifactId}</applicationName>

<environment>Sandbox</environment>

<workerType>${workerType}</workerType>

<workers>1</workers>

<objectStoreV2>true</objectStoreV2>

<region> ${region} </region>

</cloudHubDeployment>

</configuration>

</plugin>

4. Commit these files in GitHub repository. After one minute automatically one build will be triggered in Jenkins dashboard and application will be deployed to cloud hub.

5. You can check the build status under “build status” console view under “console output”.

Now check the application status in cloudHub and you are done!!

Conclusion:

You can check the internal CI/CD steps in the Jenkins dashboard under pipeline steps:

In case you want to add something, let me know in the comment section. Thank you !! :)

--

--

Priyanka Paul

Hello Techies, I love to learn and grow. Currently working as mulesoft Developer @Salesforce . I have experience in both backend(java) and middleware (MuleSoft)