CI/CD setup of MuleSoft (Cloudhub 2.0) using GitLab

Archana Devi
Another Integration Blog
4 min readMay 14, 2024

Introduction

This blog covers the basic CI/CD setup using GitLab for MuleSoft applications targeted for Cloudhub 2.0.

Purpose

Once the development of a new mule application or the changes in existing mule application is completed, and the developer pushes the codes in to the GitLab project repository, the respective CI/CD pipeline of the project is triggered and which will first build the project, publish the artifacts on Anypoint Exchange and then eventually deploy the build to the Cloudhub 2.0 runtime manager.

CICD configuration in MuleSoft application

Below changes are required in the MuleSoft application to prepare it for CICD setup.

Maven Plugin Configuration

Configure deployment details specific to Cloudhub 2.0 in the pom file of the project.

Below screenshot shows an example of the POM snippet covering CloudHub2.0 configuration.

The developer will need to supply the values of the highlighted variables in the maven command later.

In pom file below configuration should also be present for publishing artifacts on exchange: -

<distributionManagement>
<repository>
<id>Repository</id>
<name>Corporate Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/ORGANIZATION_ID/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>

Note: — Replace “ORGANIZATION_ID” with the actual Id of the business group.

Project repository in the GitLab

The project repository will require two additional files “.gitlab-ci.yml” file and “ci-settings.xml” at project directory level.

ci-settings.xml configuration:

Create a ci-settings.xml file to define credentials of Anypoint platform required to publish the artifacts on Anypoint exchange.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers>
<server>
<id>anypoint-exchange-v3</id>
<username>${username}</username>
<password>${password}</password>
</server>
</servers>
<mirrors/>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>

Pipeline configuration using “.gitlab-ci.yml”:

The “.gtlab-ci.yml” file defines the configuration of the GitLab pipeline. The configuration covers the runner which can be a docker image to spin a container to run the pipeline tasks or an agent running on a server. It also defines the rules that control when the pipeline will be triggered and the stages and jobs to cover various tasks, and the relations/dependencies among the jobs.

image: maven:3.8.2-jdk-8

stages:
- build_and_publish
- deploy
build_and_publish:
stage: build_and_publish
script:
- echo "Build and publish artifact on Anypoint exchange."
- mvn -DskipTests clean deploy -s ci-settings.xml
deploy:
stage: deploy
script:
- echo "Deploy application on runtime manager"
-mvn -DskipTests mule:deploy -DmuleDeploy -Dmule.artifact="/path/to/jar/dummy.jar" -DenvName="dev" -Denv="DEV" -Duser=$username -Dpass=$password

Store credentials and other environment specific details using variables in GitLab:

Path in GitLab: — Go to Settings -> CI/CD -> Variables -> Click on “Expand” button to add variables with their values

Executing pipeline

Path in GitLab: — Go to Project-> Build -> Pipelines -> Run Pipeline

Check Results and Logs:

Click on the jobs to see the logs and their status.

Application deployed on Cloudhub 2.0

Check the runtime manager to verify the application is deployed.

Summary:

This was one of the easiest working examples of a GitLab CI/CD pipeline that deploys a mule application on Cloudhub 2.0. We will cover more detailed examples in following blogs.

Thank you.

--

--