Automate Deployment to CloudHub using CloudHub Deployer Plugin Jenkins

DZone 's Guide to

Automate Deployment to CloudHub using CloudHub Deployer Plugin Jenkins

Learn how to deploy Mule applications to CloudHub using Cloudhub deployer Jenkins plugin, and achieve continuous delivery and deployment.

· DevOps Zone ·
Free Resource


We live in an age, Where DevOps and automation are becoming more and more necessary and important in projects. So uploading packages manually to servers or platforms is not feasible and salable when you work with architecture like micro-services. So to tackle this problem we need to implement Continuous Delivery and Deployment cycle in our project. In this post I will be showing you how to do exactly that with Mule applications.

After creating a basic Mule App, you might be wondering how to automate the process of deploying a Mule App to CloudHub. In this post, I will be introducing a Jenkins plugin(Github Repository) that I published recently that enables this use case. 

How it is compared to other solution/tools available with Jenkins:

Mule-Maven plugin - With this approach you are tight coupling you build and deploy process and most of time its not good. And its hard to scale this approach when you have multi environment deployment and many applications to manage. This approach will not work if you just want to do deployment.

This approach will take time and effort to get working automation that meets your project requirement. The CloudHub Deployer plugin itself is built using same API why re-invent the wheel.

What we will accomplish here:

Jenkins release pipeline using both free style and pipeline script that automates your mule application deployment to CloudHub.


  1. You will need to have Jenkins instance up and running. 
  2. A CloudHub account.
  3. You need to have a already built package to follow along. Since I am not covering CI(Continuous Integration) for mule apps, there are plenty article on internet for that. 

Deploying Using Freestyle Job

Step 1: Plugin Installation

Go to Manage Jenkins -> Manage Plugins -> Click on "Available" tab -> search for "cloudhub deployer"(just cloudhub will also do) -> select the plugin and click on install.

Cloudhub deployer

Step 2: Create Jenkins Job (freestyle)

Jenkins jobs

Step 3: Plugin Initialization

You can find the Cloudhub deployer under "Build" section of job configuration.

Build section

Step 4: Plugin Configuration

For a few of the repetitive configurations, you can set them at plugin global configuration under Cloudhub Settings in "Configure System". The global settings will be overridden if you also configure them in job configuration. 

CloudHub global settings

Build Step Config

If you want to inherit these configuration from global configuration check the "Use global settings"

Global configurations

Or else configure them here by unchecking the "Use global settings" checkbox.

Uncheck use global settings

Here you need to provide the organization id, environment id (you can get these from Access management console in CloudHub) and login credentials(make sure they have right amount of permission to perform actions on CloudHub like create, update delete, etc). Set the request and response timeout default is 2 minutes. And if something goes in deployment or job fails enable debug mode print all info.

API Configuration

In this section enter the application name, select the type of request you want to perform against application.

Check the autostart checkbox if you want your application to get started after deployment. Enter mule runtime version to use in cloudhub and region. Use help section of plugin if not clear with any field.

Type of Requests: 

  1. CREATE - Deploy/Create new application 
  2. UPDATE - Update application with new package and settings provided. 
  3. UPDATE_FILE - Update just the zip/jar file of application, rest all settings ignored. 
  4. CREATE_OR_UPDATE - Deploy/Create new application(if not already present) or update the existing application with settings provided.
  5.  RESTART - Restart the application already present.
  6. DELETE - Delete the application.

Package file path

Enter the package location relative to Jenkins workspace. Can be both zip and jar file. Regex can also be used here but it should resolve to a single file path other-wise job will throw error.

Worker Settings

In this we need to provide configurations related to worker/instance. which is number of worker to run, type of each worker, worker CPU and RAM size (check MuleSoft Documentation for more details on this).

Additional settings

Settings here are all optional can be enabled based on requirement. Click on plugin help section for additional detail on each option.

Add Environment key

Settings here are also optional can be set if needed. You can add key value list to application environment and additional log levels with categories to include in logs. 

Advanced Options

Application takes time to start in CloudHub after deployment or update operation, It can vary from seconds to minutes before you can access your deployed changes. If you check "Verify Deployment" then the jenkins job will wait for application to start in cloudhub before showing success. Jenkins job will ping the cloudhub for application status at interval which is specified in verify interval field.

After all the configurations are done apply and save the changes.

Step 3: Trigger the Job

Console output

You can login to CloudHub and check your application will be successfully deployed there.

Deploying Using Jenkins Pipeline Script

Step 1: Create the Pipeline Job

Item name


Step 2: Write script

Usually in a real scenario you check in the script along with code in source code repository but for this demo will add the script directly in pipeline job. 



import org.jenkinsci.plugins.cloudhubdeployer.common.*;
import org.jenkinsci.plugins.cloudhubdeployer.data.*;
pipeline {
    agent any
    stages {
        stage('Deploy') {
            steps {
                cloudhubDeployer(environmentId :'<insert env id here>', orgId :'<insert org id here>', requestMode : RequestMode.UPDATE , appName :'jenkins-deployplugin-api', credentialsId :'CLOUDHUB_ACCESS', muleVersion :'4.3.0', region :'us-east-1', filePath :'target/*.jar', timeoutConnection : 90000, timeoutResponse : 90000, debugMode : DebugMode.DISABLED, ignoreGlobalSettings : true,autoStart : true, workerAmount : 1, workerType : 'Small',workerWeight : '0.2',workerCpu : '0.2', workerMemory : '1 GB', monitoringEnabled : true, monitoringAutoRestart : true, loggingNgEnabled : true, persistentQueues : false, persistentQueuesEncrypted : false, objectStoreV1 : false, envVars : [envVars(key : 'env' , value :  'sandbox')], logLevels : [logLevels(levelCategory : LogLevelCategory.DEBUG ,packageName : 'some.package.name')], verifyDeployments : true)

If you get an error in deployment saying 

Scripts not permitted to use staticField org.jenkinsci.plugins.cloudhubdeployer.common.RequestMode UPDATE.

then you need to approve the script signature in Script Approval under Manage Jenkins. Do this for all similar error (this is one-time process).

If you want to use global setting set the 'ignoreGlobalSettings' to false and remove the unnecessary fields from code. More examples script for all other request can be found here

Step 3: Trigger the Pipeline

Stage view

Console output

You can login to CloudHub and check your application will be successfully deployed there. 

Congratulation you have successfully deployed your application to CloudHub. 

Features that will be coming soon to plugin: 

  • Ability to deploy using env and organization name instead of id.
  • Support for Autoscale policies
  • Support for Load balancer mapping
  • Support for API manger

Thanks for reading!

cloudhub, deployment, deployment automation, integration, jenkins, jenkins automation, jenkins pipeline, mule, mulesoft

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}