Mulesoft Deployment using Maven and Jenkins Plugin

03 Dec 2020

blog details

Mulesoft Deployment using Maven and Jenkins Plugin

By: RSDigitech | Published At : 03 Dec 2020    


Mule Runtime Version: 4.2.2

Jenkins version: 2.233

Mule Maven Plugin Version: 3.3.5

Deploying mule app using Maven and Jenkins

Add the Mule Maven Plugin to a Mule Project

Before you can perform any operations, you must add the Mule Maven plugin to your project.

To add the Mule Maven plugin, you need to add its maven dependency to the project:

<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-maven-plugin</artifactId>
  <version>3.3.2</version>
  <extensions>true</extensions>
</plugin>

From this repository:

<pluginRepositories>
  <pluginRepository>
    <id>mule-public</id>
    <url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
  </pluginRepository>
</pluginRepositories>

This enables the Mule Maven plugin in your project.

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

Configure the CloudHub Deployment Config Parameters

Configure the CloudHub deployment strategy in your project’s pom.xml file so you can deploy, redeploy and undeploy your Mule application using the Mule Maven plugin.

Inside the plugin element in your project’s pom.xml file, configure your CloudHub deployment, replacing the placeholder values with your CloudHub information:

<plugin>

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

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

  <version>3.3.2</version>

  <extensions>true</extensions>

  <configuration>

   <cloudHubDeployment>

    <uri>https://anypoint.mulesoft.com</uri>

    <muleVersion>${app.runtime}</muleVersion>

    <username>${username}</username>

    <password>${password}</password>

    <applicationName>${cloudhub.application.name}</applicationName>

    <environment>${environment}</environment>

    <properties>

     <key>value</key>

    </properties>

   </cloudHubDeployment>

  </configuration>

</plugin>

 

Example: 

plugin xml

 

Deploy to CloudHub

From the command line in your project’s folder, package the app and execute the deploy goal:

mvn clean package deploy -DmuleDeploy

Redeploy to CloudHub

To redeploy a Mule application using Mule Maven plugin, run mvn clean package deploy -DmuleDeploy as you did to previously deploy the app. CloudHub rewrites the app you had deployed.

Undeploy from CloudHub

To undeploy a Mule application using Mule Maven plugin, run the following command:

mvn mule:undeploy

The undeploy command also deletes the app in Mule Maven plugin 3.3.0 and later versions.

Jenkins Deployment Job Configuration

Maven Configuration in Jenkins Global Tools Configuration

maven installation

We can specify project folder as custom workspace for Jenkins job, otherwise it will use its default workspace path which points to “C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace\mule-jenkins-deploy”

mule jenkins deploy

Build command

mvn clean package deploy -DmuleDeploy -Dmule.version="4.2.2" -Danypoint.username="test_rsd" -Danypoint.password="******" -Dcloudhub.app="test-api-rsd-dev" -Dcloudhub.environment="Sandbox" -Dcloudhub.bg="rsd" -Dcloudhub.worker="micro"

Batch Command

If -DmuleDeploy is not specified as paramter below error will occur

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MuleCICDWithJenkins: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]

 

deploy goal

Deployment might fail with below error if <objectStoreV2>true</objectStoreV2> tag is not included in cloudhub deployment configuration in pom.xml

Deploy fails caused by org.mule.tools.client.core.exception.ClientException: 400 Bad Request: {"status":400,"message":"Object Store V1 is not supported for your org"}

**********************************************************************

Jenkins Deployment with Git as SCM

Source Code Management

Build Triggers

 

Batch Command

In the above build command I have used “cd test-project” as my git repository master branch has folder with project name “test-project” and pom.xml file is present inside the folder, we need to specify path such that pom.xml file is reachable and maven goals can be executed

Git Managed

Git Managed

 

Reference Links:

https://docs.mulesoft.com/mule-runtime/4.1/mmp-concept

https://docs.mulesoft.com/mule-runtime/4.1/deploy-to-cloudhub#cloudhub-deploy-reference

https://help.mulesoft.com/s/question/0D52T00004xJUgESAW/mule-4-cannot-deploy-mulesoft-application-to-cloudhub-using-mule-maven-plugin

Technologywe use

  • PHP
  • Angular
  • Android
  • Laravel
  • Salesforce
  • Tibco
  • Mulesoft