Sitemap

CICD Jenkins Pipeline: MuleSoft

4 min readNov 30, 2021

--

Press enter or click to view image in full size

Introduction

CI/CD or CICD is the combined practices of continuous integration (CI) and either continuous delivery or continuous deployment (CD).

CI/CD bridges the gaps between development and operation activates and teams by enforcing automation in building, testing and deployment of applications. The process contrasts with traditional methods where all updates were integrated into one large batch before rolling out the newer version. Modern day DevOps practices involve continuous development, continuous testing, continuous integration, continuous deployment and continuous monitoring of software applications throughout its development life cycle.

CICD

1. Creating a Sample application

2. How to create profiles in pom.xml

3. Deploy into cloud hub using CICD

4. Creating pipelines with hardcoded properties values

5. Externalize runtime properties in Jenkins

1. Creating a Sample application:

  • Here I created sample application with Dev and Test yaml files.
  • Created separated global.xml for all global configuration elements.
Press enter or click to view image in full size
Global Configuration Elements

Dev.yaml:

Press enter or click to view image in full size
Dev.yaml

Test.yaml

Press enter or click to view image in full size
Test.yaml

2. How to create profiles in pom.xml

Creating profile for Dev and Test:

<profiles>

<profile>

<id>dev</id>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-clean-plugin</artifactId>

<version>3.0.0</version>

</plugin>

<plugin>

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

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

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

<extensions>true</extensions>

<configuration>

<cloudHubDeployment>

<applicationName>Sample-dev-jekins-example</applicationName>

<environment>Dev</environment>

<region>us-east-1</region>

<workers>1</workers>

<workerType>MICRO</workerType>

<properties>

<httpport>8081</httpport>

<env>dev</env>

<enc.key>${enc.key}</enc.key>

<api.id>17421405</api.id>

<anypoint.platform.client_id>${anypoint.platform.client_id}</anypoint.platform.client_id>

<anypoint.platform.client_secret>${anypoint.platform.client_secret}</anypoint.platform.client_secret>

</properties>

</cloudHubDeployment>

<classifier>mule-application</classifier>

</configuration>

</plugin>

<plugin>

<groupId>com.mulesoft.munit.tools</groupId>

<artifactId>munit-maven-plugin</artifactId>

<version>${munit.version}</version>

<executions>

<execution>

<id>test</id>

<phase>test</phase>

<goals>

<goal>test</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

</profile>

<profile>

<id>test</id>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-clean-plugin</artifactId>

<version>3.0.0</version>

</plugin>

<plugin>

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

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

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

<extensions>true</extensions>

<configuration>

<cloudHubDeployment>

<applicationName>Sample-dev-jekins-example-test- sapi</applicationName>

<environment>test</environment>

<region>us-east-1</region>

<workers>1</workers>

<workerType>MICRO</workerType>

<properties>

<httpport>8081</httpport>

<env>test</env>

<enc.key>${enc.key}</enc.key>

<api.id>17426137</api.id>

<anypoint.platform.client_id>${anypoint.platform.client_id}</anypoint.platform.client_id>

<anypoint.platform.client_secret>${anypoint.platform.client_secret}</anypoint.platform.client_secret>

</properties>

</cloudHubDeployment>

<classifier>mule-application</classifier>

</configuration>

</plugin>

</plugins>

</build>

</profile>

</profiles>

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

Get mani mulesoft’s stories in your inbox

Join Medium for free to get updates from this writer.

<artifactId>maven-clean-plugin</artifactId>

<version>3.0.0</version>

</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>4.4.0</muleVersion>

<username>${username}</username>

<password>${password}</password>

<objectStoreV2>true</objectStoreV2>

<properties>

<env>sandbox</env>

<anypoint.platform.base_uri>https://anypoint.mulesoft.com/</anypoint.platform.base_uri>

<anypoint.platform.analytics_base_uri>https://analytics-ingest.anypoint.mulesoft.com/</anypoint.platform.analytics_base_uri>

</properties>

</cloudHubDeployment>

<classifier>mule-application</classifier>

<sharedLibraries>

<sharedLibrary>

<groupId>mysql</groupId>

<artifactId>mysql-connector-java</artifactId>

</sharedLibrary>

</sharedLibraries>

</configuration>

</plugin>

</plugins>

</build>

3. Deploy into cloudhub using CICD:

1. Select Maven project

2. In Source Code Management:

  • We have to provide git repository URL and Credentials and Branch

In build:

In Root POM: we have to provide file name — Pom.xml

In Goals and options:

mvn clean package deploy -Pdev -DmuleDeploy -Dusername=mani -Dpassword=Ma***00 -Denc.key=qwerty987654321 -Danypoint.platform.client_id=b5380b80479645308fa3c1853e314501 -Danypoint.platform.client_secret=248844e0C9124fa4eE6AE070d752

Press enter or click to view image in full size
Creating Maven Project

Git Configuration in Source code management:

Press enter or click to view image in full size
Git configuration

Final output:

Press enter or click to view image in full size
output console

4. Creating pipelines with hardcoded properties values:

Press enter or click to view image in full size
Creating pipeline

Git Configuration with Pipeline Script from SCM:

Press enter or click to view image in full size
pipeline configuration

Jenkinsfile:

pipeline {

agent any

stages {

stage(‘Build’) {

steps {

echo ‘Application is in Building Phase’

bat ‘mvn clean install’

}

}

stage(‘Test’) {

steps {

echo ‘Application is in Testing Phase’

bat ‘mvn test’

}

}

stage(‘Deploy to Cloudhub’) {

steps {

bat ‘mvn clean package deploy -DmuleDeploy -Pdev -Dusername=mani -Dpassword=Manimani -Denc.key=qwerty987654321 -Danypoint.platform.client_id=b5380b80479645308fa3c1853e314501 -Danypoint.platform.client_secret=248844e0C9124EAfa4eE6ceAE070d752’

}

}

}

}

Final Stage View:

Press enter or click to view image in full size
Stage View

5. Externalize runtime properties in Jenkins

Press enter or click to view image in full size
Creating Pipeline

Creating credentials:

Press enter or click to view image in full size
Creating Credentials

Git Configuration with Pipeline Script from SCM:

Press enter or click to view image in full size
Git Configuration

Jenkinsfile:

pipeline {

agent any

environment {

MY_CRED = credentials(‘anypointPlatform’)

MY_KEY = credentials(‘anykeykey’)

MY_CLIENT = credentials(‘anyclientid’)

MY_SECRET = credentials(‘anykeysecret’)

}

stages {

stage(‘Build’) {

steps {

echo ‘Application is in Building Phase’

bat ‘mvn clean install’

}

}

stage(‘Test’) {

steps {

echo ‘Application is in Testing Phase’

bat ‘mvn test’

}

}

stage(‘Deploy to Cloudhub’) {

steps {

bat ‘mvn clean package deploy -DmuleDeploy -Pdev -Dusername=%MY_CRED_USR% -Dpassword=%MY_CRED_PSW% -Denc.key=%MY_KEY% -Danypoint.platform.client_id=%MY_CLIENT% -Danypoint.platform.client_secret=%MY_SECRET%’

}

}

}

}

Stage View:

Press enter or click to view image in full size

Application deployed in Cloud Hub:

Press enter or click to view image in full size
Deployed Application

Reference: http://workshop.tools.mulesoft.com/modules/module7_lab4

--

--

mani mulesoft
mani mulesoft

Written by mani mulesoft

Certified MuleSoft (Mule 4) Developer & Dell Boomi Associate Developer | Software Engineer