Mulesoft CI-CD Setup

 

Let’s see how we setup Mulesoft CI-CD

Prerequisite:

  • JDK
  • Maven
  • Jenkins or any other continuous integration tool
  • github or any other scm tool for source code management
  • Anypoint Studio

If you have not set up the Jenkins and github, please follow the earlier post in this series, part-1 to setup the github and part-2 to set up the jenkins

In this tutorial I will demonstrate how can we automate the deployment on cloudhub for mulesoft application using jenkins/github, Please follow the below steps.

Create sample project in anypoint studio

Mulesoft CI-CD Setup

 

 

Add the plugin in pom.xml with cloudhubDeployment configuration

<plugin>
	<groupId>org.mule.tools.maven</groupId>
	<artifactId>mule-maven-plugin</artifactId>
	<version>3.3.5</version>
	<extensions>true</extensions>
	<configuration>
		<cloudHubDeployment>
			<uri>https://anypoint.mulesoft.com</uri>
			<muleVersion>4.2.2</muleVersion>
			<username>mulepoc</username>
			<password>*******</password>
			<applicationName>mulesoft-cicd-sample1</applicationName>
			<environment>Sandbox</environment>
			<workerType>MICRO</workerType>
			<objectStoreV2>true</objectStoreV2>
		</cloudHubDeployment>
	</configuration>
</plugin>

 

Sample pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.mycompany</groupId>
	<artifactId>mulesoft-cicd-sample1</artifactId>
	<version>1.0.0-SNAPSHOT</version>
	<packaging>mule-application</packaging>

	<name>mulesoft-cicd-sample1</name>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

		<app.runtime>4.2.2</app.runtime>
		<mule.maven.plugin.version>3.3.5</mule.maven.plugin.version>
	</properties>

	<build>
		<plugins>
			<plugin>
				<groupId>org.mule.tools.maven</groupId>
				<artifactId>mule-maven-plugin</artifactId>
				<version>3.3.5</version>
				<extensions>true</extensions>
				<configuration>
					<cloudHubDeployment>
						<uri>https://anypoint.mulesoft.com</uri>
						<muleVersion>4.2.2</muleVersion>
						<username>mulepoc</username>
						<password>**********</password>
						<applicationName>mulesoft-cicd-sample1</applicationName>
						<environment>Sandbox</environment>
						<workerType>MICRO</workerType>
						<objectStoreV2>true</objectStoreV2>
					</cloudHubDeployment>
				</configuration>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<dependency>
			<groupId>org.mule.connectors</groupId>
			<artifactId>mule-http-connector</artifactId>
			<version>1.5.11</version>
			<classifier>mule-plugin</classifier>
		</dependency>
		<dependency>
			<groupId>org.mule.connectors</groupId>
			<artifactId>mule-sockets-connector</artifactId>
			<version>1.1.5</version>
			<classifier>mule-plugin</classifier>
		</dependency>
	</dependencies>
	<repositories>
		  <repository>
			<id>anypoint-exchange-v2</id>
			<name>Anypoint Exchange</name>
			<url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
			<layout>default</layout>
		</repository>
		<repository>
			<id>mulesoft-releases</id>
			<name>MuleSoft Releases Repository</name>
			<url>https://repository.mulesoft.org/releases/</url>
			<layout>default</layout>
		</repository>
	</repositories>
	<pluginRepositories>
		<pluginRepository>
			<id>mulesoft-releases</id>
			<name>mulesoft release repository</name>
			<layout>default</layout>
			<url>https://repository.mulesoft.org/releases/</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</pluginRepository>
		<pluginRepository>
	<id>mule-public</id>
	<url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
  </pluginRepository>
	</pluginRepositories>
</project>

Note: If <extensions>true</extensions> is not present, the plugin does not work.

Create new item as freestyle project in Jenkins

Mulesoft CI-CD Setup

 

Click on configure

Mulesoft CI-CD Setup

 

Configure the git hub project url

 

Configure git repository

 

Configure the deploy command

 

Configure the cron expression to trigger build every one minute

 

Build get triggered and success

 

Build is now success


Project deployed successfully on cloudhub

 

Note: I got the below error while deployment

Caused by: org.mule.tools.client.core.exception.ClientException: 400 Bad Request: {“status”:400,”message”:”{name=null, workerVal=null, cpu=null, memory=null} is not a valid value for worker.type.name.”}

Solution: Add the below tag in cloudhub configuration

<workerType>MICRO</workerType>

 

Caused by: org.mule.tools.client.core.exception.ClientException: 400 Bad Request: {“status”:400,”message”:”Object Store V1 is not supported for your org”}

Solution: Add the below tag in cloudhub configuration

<objectStoreV2>true</objectStoreV2>

 

Test the project from soap ui

 

Sample application: mulesoft-cicd-sample application

 

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Raj Chaudhary
Raj Chaudhary
3 years ago

Hi,

In this tutorial, you have hard coded CH credentials in pom.xml. Is there a way to externalize those creds? This way we could use same pipeline for different envs.

Cheers
Raj

Maciek
Maciek
9 months ago
Reply to  admin

Not exactly. You need more than just adding Maven command line parameters. Hardcoding those for Maven is also not a smart idea.

ngffgf
ngffgf
2 years ago

In “General” tab, you’ve provided the GitHub project URL same as Repository URL.
Its giving me errors while setting GitHub project URL that pom.xml not exists.
Please assist me how can I provide GitHub project URL for following project:
I’ve a develop branch and under develop branch I’ve a project named “sample-muleapp-cicd



Last edited 2 years ago by ngffgf
Prachi
Prachi
2 years ago

C:\Users\ACS\.jenkins\workspace\myfirstproject>mvn clean package deploy -DmuleDeploy
‘mvn’ is not recognized as an internal or external command,
operable program or batch file.

C:\Users\ACS\.jenkins\workspace\myfirstproject>exit 9009
Build step ‘Execute Windows batch command’ marked build as failure
Finished: FAILURE

help please!

Maciek
Maciek
9 months ago

That is good enough if you deploy to one environment. So you create projects like that for every VPC environment? Perhaps it is time to show how it is done with Maven profiles. Plus you do not want to have credentials on project POM. In finance there is strict segregation of roles and developers cannot have passwords to production environments. that is reserved to DevOps.

Last edited 9 months ago by Maciek
Maciek
Maciek
9 months ago

How about showing how to build separately and deploy to Artifactory or Nexus and have separate projects that are used by DevOps to deploy only without building (you are not building flows and binaries for different environments every time you need to deploy runtime to platform) taking prebuild JAR from binary repository? In fact, this should be doable many times (idempotent operation) if anything VPC changes or needs rebuild without rebuilding software in Jenkins.