Deploy Mule Application To CloudHub Via Jenkins Multi Branch Pipeline

Author: Ayesha Saoji

The purpose of this article is to:

Set up a Jenkins Multi Branch pipeline if you wish to deploy your Mule application to CloudHub to the respective CloudHub Environment as per the repository branch.

   Ex. If you wish to Deploy “master” branch code to CloudHub “Production Environment.

   And  If you wish to Deploy “Dev” branch code to CloudHub “QA Environment,” etc.

In the above scenarios, you need to set up a Multi Branch Pipeline to deploy the Mule Application to the respective CloudHub environment depending on the branch on which code was recently committed.

Below are the steps to deploy a mule application to cloubHub via Jenkins Multi Branch Pipeline.

1)  Install JDK on your local machine.

2)  Install Maven on your local machine.

After completing installation :

    Create a new folder with the name Maven in the C Drive of your computer.

    Install Maven at location C:\Maven by extracting the downloaded Maven.

Set the System Variables for JAVA_HOME and MAVEN_HOME in environment variables.

Under System variables set below paths:

Set PATH variable in System variables to below values:

3) Sign In to BitBucket Account

4) Install Jenkins Server

Follow the below steps to setup Jenkins :

Let’s add the required maven plugin first.

   Step 1 – Go to Jenkins Dashboard > Manage Plugin.

 Step 2 – Go to the Available tab and search for “Maven Integration Plugin” and Install that and then it will come to the Installed tab as shown below.

Create a New Mule Application and do below settings in the POM.xml file to add maven-plugin dependency

Add it inside mule-maven-plugin












The values from the configuration section like ${username} , etc. will be coming from below command from Jenkins Script.

bat ‘mvn clean package deploy -Dusername=${ANYPOINT_CREDENTIALS_USR} -Dpassword=${ANYPOINT_CREDENTIALS_PSW} -DapplicationName=<YourApplicationName> -Denvironment=<YourCloudHubEnvironmentName> -Dworkers=1 -DworkerType=Micro -DobjectStoreV2=true -DmuleDeploy’

And the credentials i.e. ${ANYPOINT_CREDENTIALS_USR} and ${ANYPOINT_CREDENTIALS_PSW} will be coming from Jenkins Global Configuration as shown below:

GoTo Jenkins Dashboard > Manage Jenkins > Manage Credentials > Add new Credentials 

Select Scope as shown below and set ID as specified and UserName = AnyPoint Platform UserName and Password = AnyPoint Platform Password.

Jenkins Script File  (Add it on the Project level , i.e. on the same level as the POM.xml file.)

 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’) { 

                   environment {

                                 ANYPOINT_CREDENTIALS = credentials(‘platform.credentials’)


                   steps { 

bat ‘mvn clean package deploy -Dusername=${ANYPOINT_CREDENTIALS_USR} -Dpassword=${ANYPOINT_CREDENTIALS_PSW} -DapplicationName=DemoJenkinsApplication -Denvironment=Sandbox -Dworkers=1 -DworkerType=Micro -DobjectStoreV2=true -DmuleDeploy’





Create a new repository and deploy your Mule Application to BitBucket.

5) Follow the below steps to setup Jenkins Multi Branch Pipeline:

Step 5.1: Go To Jenkins Dashboard and select New Item to create a Multi Branch Pipeline.

Step 5.2:  Add Basic details like Pipeline description and GitHub or BitBucket Repository URL, etc. Configure the credentials as well by specifying ID and Password.

      ID is your BitBucket ID, and Credentials will be BitBucket Password.

 While Configuring BitBucket URL for Jenkins Pipeline, you need to create App Password for the below scenarios:

      Note: If you have signed in to a BitBucket account via Gmail, etc., then your credentials password will not be sent. 

      So you need to create an App Password here:

Step 5.2.1: Go to Personal Settings and select App Password.

      Step 5.2.2: Click on Create app password.

     Step 5.2.3: Create a new label and set required permissions.

Step 5.2.4: Click on the create button, and you will get your new app password which you can set as Password in credentials while doing the below configuration.

Step 5.3: Now for Click on Discover Branch so that our pipeline will create a Pipeline for all the branches available in Git/BitBucket repository. Select strategy as specified below. Also, specify the path for Jenkins Script File.

   Step 5.4: Select the duration after which you wish your pipeline to deploy the application automatically. 

   Also, configure the details to keep previous build information as per your requirement.

Step 5.5:  Click on Apply and then save the changes. 

Step 5.6:  Now, automatically, your pipeline will start scanning the branches available in the pipeline, and for each branch, it will check whether the branch has a Jenkins Script File or not. Depending on the availability of Script File, it will deploy applications only from branches having Jenkins Script and to the environment specified in the Script File.

   Step 5.7: Repository information and pipeline information. 

                   In the repository, here we have two branches: “master” and “Dev.”

   A pipeline has also been created for both the branches since both branches had the respective script file.

Step 5.8: Successful deployment of Mule Application.

Now Log In to the MuleSoft AnyPoint Platform and see that your Mule Application has been successfully deployed to CloudHub and it is up and running after setting up your Jenkins Multi-Branch Pipeline.

Conclusion: We have successfully deployed our Mule Application to CloudHub by setting up a BitBucket Code Repository and a CI/CD Multi Branch pipeline in Jenkins.

Thanks for Reading !!

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.