Deploying Mule Application On RTF By Jenkins CI/CD Pipeline Using GitLab

Authors:  Shubham Bhosale & Rohit Singh

Introduction:

In this blog, we will see how we can deploy a simple Mule application on RTF through Jenkins Pipeline using GitLab.

What is CI/CD?

CI is a short form for Continuous Integration, is a software development practice in which all developers merge code changes in a central repository multiple times. 

CD stands for Continuous Delivery, which on top Continuous Integration adds the practice of automating the entire software release process.

Prerequisites for RTF CI/CD pipeline with MuleSoft Using Jenkins:
  • Anypoint Studio to develop your application
  • Jenkins
  • An active Anypoint Platform account
  • Maven and Git installed on your local system
  • RTF Setup on Anypoint Platform account
  • Plugins to be added on Jenkins – Config File Provider Plugin (to pass the Settings.xml file) and GitLab API Plugin

Note: In the demonstration confidential fields are masked.

Steps to perform:

Step 1. Create a project in AnyPoint studio which you wish to deploy on RTF. For this blog, we’ll take a simple example which consists of an HTTP Listener and a Transform Message component.

Step 2: Now configure your project’s pom.xml to enable the deployment of your project on RTF via maven. This uses mule-maven-plugin which is already a part of your pom.xml generally, in case it is missing just add the dependency and use the following configuration for Runtime Fabric Deployment.

Step 3: There are few prerequisites before we deploy our application to RTF, one of those is the application that has to be deployed in exchange first, otherwise it will give GAV not found error. To avoid this, we need to add below code in our pom.xml file so it will publish the application to exchange first.

<distributionManagement>
 	<repository>
 	<id>anypoint-exchange</id>
 	<name>Exchange Repository</name>
         <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/your-org-id/maven</url>
 	<layout>default</layout>
 	</repository>
</distributionManagement>

Step 4: These variables can be defined at Runtime in Jenkins file script or can be directly given in the pom.xml. For further reading on these properties or any additional flags, you can visit the official documentation on https://docs.mulesoft.com/mule-runtime/4.3/deploy-to-rtf#prerequisites.

Step 5: Add the AnyPoint platform credentials in the settings.xml file. We can put this settings.xml file in the Jenkins. Please note the File ID for the setting.xml file it will be required in the further process.

<server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
</server>

Step 6: Create a Script in the Jenkins file for pipeline execution.

Below is the sample code for the Jenkins pipeline script:

Echo is a Unix/Linux command tool used for displaying lines of text or string which are passed as arguments on the command line.

We can pass values in Jenkins script which will be passed into the CloudHub for RTF configuration like CPU limit, memory allocation, etc.

Step 7: Put your code to a GitLab repository along with the Jenkins file.

Step 8: Configure the Jenkins pipeline.

A. Create one pipeline job.

  • Under Pipeline tag do the following configurations.
  1. Definition – Pipeline Script from the SCM
  2. SCM – GIT
  3. Repository URL – URL of the repository from which we want to pick up the code
  4. Credentials –  Store securely the GitLab credentials in the Jenkins
  5. Branch – Give the branch name from which you want to pick up Build e.g main or feature
  6. Script Path – Give the Name as Jenkinsfile because we stored the script in this file

Step 9: Click on Build button your pipeline, it will start running and you will see successful deployment in RTF.

Step 10: If you want to automatically trigger the pipeline, then we need to set up Webhooks or Integrations under the settings tab in GitLab.

Click on Integrations and Add an Integration – Jenkins. Then fill following fields:

  • Enable integration – Tick this option
  • Trigger – Tick Push (Trigger event for pushes to the repository). You can add other trigger options also according to your requirements
  • Add Jenkins server URL
  • Project Name – The name of the Jenkins Project. Copy the name from the end of the URL to the project
  • The username for the Jenkins server
  • The password for the Jenkins server

Summary

In this blog, we have understood the process of Deployment for RTF using CI/CD Pipeline. We got to know about the configuration of Jenkins and GitLab for successful deployment in the RTF.

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.