MuleSoft Automate Deployment

Deploy Mule Applications to CloudHub using the Mule Maven Plugin and Bitbucket Pipelines

Kuldeep Bhati
apigeek
4 min readMar 11, 2021

--

Credit: Atlasssian (BitBucket)

Hello and welcome. In this post I will explain how to automate MuleSoft Application deployment to CloudHub using Mule Maven Plugin and Bitbucket Pipeline.

Prerequisite

  • MuleSoft CloudHub Account
  • Bitbucket Atlasssian Account — for code repository.
  • If you are using the HTTP Listener as source for your flow, you need to set its host to 0.0.0.0 and its port to ${http.port}
  • Declare all external classes and resources in the exportedPackages and exportedResources fields on the mule-artifact.jsonfile.

Project Structure

Pipeline file should have the name — bitbucket-pipelines.yml. It should be at repository root-level as described below in a sample project structure. Once it is defined at the root-level, Bitbucket will automatically pick-up any changes to the code commit and will start to run the pipeline.

Pipeline Stages

  1. Git Security Scan
  2. Validate & Compile
  3. Test
  4. Deploy to Sandbox CloudHub

Alright, a big question — how to integrate this pipeline to a MuleSoft Project? Let’s check this out in the next section.

How to integrate pipeline to your own MuleSoft Project

  1. Update pom.xml: open pom.xml — plugin element: Inside the plugin element in your project’s pom.xml file, search for plugin section with mule-maven-plugin artifactIdand replace the below pluginplaceholder.

2. Create Variable References in Bitbucket: In step 1, as you can see, we are using pipeline variables e.g. — {MULESOFT_ENVIRONMENT} . These pipeline variables are convenient as you can set these once and reuse in your pipeline at build time.

  • So let’s create Workspace Variablesas described below;
Bitbucket Workspace Variables

The reason we’re using Workspace Variables is for the reusability. Once defined, can be reused within the workspace, i.e. for all repository; so you don’t have to create these variables for each and every repository within the workspace.

We’re usingMULESOFT_USERNAME and MULESOFT_PASSWORD variables as secured . Bitbucket supports variables stored as secured so it’s value is hidden and not visible in the variables list and in the build logs. Secure variables are stored as encrypted values.

  • Next, Let’s create Deployment Variables ; these variables can only be used in a specific deployment environment. We will set MULESOFT_ENVIRONMENT variables with the value of a deployment environment in your MuleSoft CloudHub, e.g. Sandbox

Ensure that the pipeline is enabled before creating Deployment Variables

  • Change the Test environment name to Sandbox ; [we’re going to use CloudHub’s Sandbox environment, you can use the one that’s available]
  • Under Variables section for the Sandbox environment, create MULESOFT_ENVIRONMENT variable with value Sandbox
Bitbucket — Repository Deployment variables

For more details about Bitbucket variables, you can visit — https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/

3. Create bitbucket-pipelines.yml as described below

4. that’s it basically, all done.

5. Push the code to your remote master branch — and Bitbucket will trigger the deployment.

Successful Deployment — BitBucket pipeline (y)
Successful Deployment — CloudHub logs (y)

Demo Project

Remember — the objective is to deploy the application to CloudHub. I have used a sample MuleSoft Application — with a Listener that returns a “Hello World!” JSON response.

Mule Application — Listener returns a simple “Hello World!” message.

You can use this repository included with pipeline configurations here — https://bitbucket.org/kuldeepbhati/cloud-hub-deploy/src/master/

Common Issues

  • 4.3.0–20210119 is not a valid value for muleVersion.version.

If you get this error; this is due to the incorrect <app.runtime>4.3.0–20210119</app.runtime> in your pom.xml file. Correct it as <app.runtime>4.3.0</app.runtime>

Important Notes

--

--

Kuldeep Bhati
apigeek

Crafts APIs, Apigee, API Architect, Mulesoft Certified Developer, Amateur Photographer — https://tinyurl.com/y7252rsg