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
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
Click on configure
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
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
You can replace the hardcoded value with ${username} and ${password} in pom.xml and can pass the argument values through Maven command line arguments e.g. mvn clean install -Dusername=usernname -Dpassword=password
Thanks,
Mulesy Team
Not exactly. You need more than just adding Maven command line parameters. Hardcoding those for Maven is also not a smart idea.
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“
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!
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.
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.