Implementing CI/CD in Mule using Jenkins
- November 24, 2021
Continuous integration/continuous deployment (CI/CD) is a method to frequently deliver apps to customers by introducing automation into the stages of app development. The main concepts attributed to CI/CD are continuous integration, continuous delivery and continuous deployment. CI/CD solves integration issues in new code that can cause problems for development and operations.
Specifically, CI/CD introduces ongoing automation and continuous monitoring throughout the lifecycle of applications, from integration and testing phases to delivery and deployment. Taken together, these connected practices are often referred to as the CI/CD pipeline. Development and operations teams support the process by working together using an Agile framework with a DevOps approach.
Prerequisites
Anypoint Platform setup
- Navigate to https://anypoint.mulesoft.com
- Check your Anypoint credentials (username and password) and deployment environment
Github setup
- Navigate to your GitHub account (https://github.com)
- Check your GitHub credentials (username and password) and log in
- Create a repository and push your code
- Save the git repository URL where you want to implement a CI/CD pipeline (https://github.com/Kishan-Jasani/bookmyholiday-ws.git)
Jenkins setup
- Download Jenkins at https://www.jenkins.io/download/
- Unzip the executable jar and host the application on port 8080
- Navigate to http://localhost:8080/ and set up an admin username and password
Project-level configuration
- Open the pom.xml file of your Mule project
- Under <plugins>, find the <plugin> tag where the <groupId> is equal to org.mule.tools.maven
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
</plugin>
- Add the <configuration> tag inside the <plugin>
<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>${mule.version}</muleVersion>
<username>${anypoint.username}</username>
<password>${anypoint.password}</password>
<environment>${env}</environment>
<applicationName>${appname}</applicationName>
<businessGroup>${business}</businessGroup>
<workerType>${vCore}</workerType>
<workers>${workers}</workers>
<objectStoreV2>true</objectStoreV2>
</cloudHubDeployment>
</configuration>
</plugin>
Setting up a CI/CD pipeline using Jenkins
- Navigate to http://localhost:8080/ and log in with the admin username and password
- Click on Manage Jenkins → Manage Credentials
- Under Stores scoped to Jenkins on the right, click Jenkins
- Under System, click the Global Credentials (unrestricted) link to access this default domain
- Click Add Credentials on the left
- Enter your GitHub username and password and click OK
- Navigate to http://localhost:8080/ and click New Item
- Enter an item name, select Free Style Project and click OK
You’ll be redirected to the configuration page
- Enter a Pipeline Description and the GitHub Project URL where you want to implement a CI/CD pipeline
- Scroll down to Source Code Management and select git
- Add the repository URL and, from the drop-down, select Credential
- Specify the branch of your repository where you want to set up your CI/CD pipeline
- Under Build Triggers, click Poll SCM and write cron expressions based on your requirements (for example, write ‘* * * * *’ if you want to check the update on repository every minute)
- Under Build, add the build step ‘Invoke top-level Maven targets’
- Select the Maven Version as ‘MAVEN_HOME’ and write ‘Goals’
Goals:
clean deploy -DmuleDeploy -DskipTests -Dmule.version=4.3.0 -Danypoint.username=<Your Anypoint Platform Username> -Danypoint.password=<Your Anypoint Platform Password> -Denv=<Your Anypoint Platform Environmanet> -Dappname=cicd-pipeline-demo -Dbusiness=Apisero -DvCore=Micro -Dworkers=1
- Copy and paste these Goals
- Click Apply
- Click Save
You’ll be redirected to Dashboard.
- Your build will start automatically, every time you change your code in the GitHub repository
- Your pipeline will start running and you’ll see the Console Output
- Your Project will start deploying automatically in your Anypoint Platform
Your CI/CD pipeline is now ready.
— By Kishan Jasani