Deploying Mule Application Using Azure DevOps — Saama Analytics

Saama Analytics
Saama Analytics
Published in
6 min readMay 14, 2021

This article uses Azure DevOps as a CI/CD tool and provides a step-by-step guide on how to deploy Mulesoft application in Anypoint cloud with Azure DevOps.

Azure DevOps is one of the leading tools that automate CI/CD’s process. The Azure pipeline combines CICD to consistently test and build the code and sends it to the target environment. It gives the software delivery process in stages like Build, Test, Merge, and Deploy.

Azure Repos will allow you to manage and version control your project code. I have used the same for this proof of concept but we can use some other repos also GITHUB, Bit bucket etc.

Methods of deployment:

  1. Doing deployment from Create pipeline itself.
    To do the deployment from create pipeline we need to configure settings.xml and add <cloudHubDeployment> in pom.xml
  2. Keeping create and release pipeline separate and doing deployment from release pipeline (best practice to control the deployments to different environments). Here we don’t need to use settings.xml or add < cloudHubDeployment > in pom.xml, we are configuring credentials in variable groups and the deployment is going to be using the Anypoint CLI command, which you will get to know soon in this blog.

Note: I am going to explain method 2 (by creating two different pipelines)

Deployment steps:

Step 1: Install GITHUB in your local machine and check in a sample code to Azure repo using GIT commands, Go inside your project location, here is an example “sample” is my project in my workspace.

Here is an example with commands. ( Commands highlighted in yellow colour) . I have already linked my local repo to remote repo, so I didn’t use the command used for linking.

Now login to Azure DevOps using your credentials ( https://dev.azure.com/ ). Create your own project by clicking the new project and keep it public or private. I have kept it private.

In the snapshot, vinohell is the organization name and sample is my project name,

Go into your project, and explore the options. Click Repos on the left side and go into your repository. We can create new branches here by clicking the default on master and also we can take the clone URL from this page too.

Click Clone and we will use the clone URL for linking the local GitHub repository to the Azure repository.

Now go to pipelines in the left side menu and click new pipeline,

After clicking the new pipeline, we can create the pipeline in two ways. One is via YAML which is a modern way and another one is using a classic editor which is highlighted below. We are going to create a pipeline using classic editor only.

A fter clicking classic editor you will get below the menu, that select project name, repo name and branch name and click continue.

After clicking Continue, we have to select MAVEN as a template. Type MAVEN in the search tab and select MAVEN template.

By default, the MAVEN template will have the below tasks already and keep it as it is and Save (don’t click save and queue now) it. Click the arrow and you will see the save option in the drop-down menu.

Before we start our pipeline creation first we will save the environment-specific variables in variables groups. Under the library section, go to variable groups and create a “Dev env” variable group. Add the environment-specific details by creating new variables. Likewise, create for 2 nd environment (UAT env) too.

Dev env variables:

This is how it will look like when you create two variable groups (highlighted in yellow)

Step 2: After creating the pipeline, you have to add 4 jobs here. Already 3 jobs are in the maven template. So for caching alone we need to add a Cache job (cache is for faster build and it will save the dependencies in cache and use it for next build thus it reduces a lot of time).

Add the below jobs using the (+) symbol

Cache settings highlighted below

Click Maven Pom.xml

Under goals add clean package command and in options add -DskipMunitTests $(MAVEN_OPTS)

Since we are not doing testing I skipped the MUnit testing and added caching command

Add Copy files job to tasks by clicking + symbol,

Copy the build .jar file to the target directory, here is the screenshot for it,

Publish the artifacts job, as shown below,

Step 3: Our CI is in manual now, to make the jobs automatic when the code checks in to our branch, in create pipeline we need to enable continuous integration by clicking the Triggers option, below is the screenshot,

Note: Now if new code checks into the project, continuous integration will happen automatically. Till now we have completed the building of jar and the next step is to configure the deployment

Step 4: Create the release pipeline, here are the available options

After clicking the new, Select Azure App service deployment

This how it should look now.

Step 6:

Step 7: Now we have to add environments in the staging layer. Click +Add

Step 8: We have configured the credentials in variables groups and we need to link them to the stages.

Follow the below steps,

To link variable groups we created to stages, first, click variables in the top menu, then click variable groups now click link variable group and you will be able to see the created variable groups from the library section.

Step 9: Click Dev stage, we will add Bash script job in tasks section by clicking (+) symbol and write any point CLI command there to deploy in cloud hub.

Step 10: Please configure pre and post-deployment approvals in the below-highlighted options, the same user or different users who have access to the azure organization can have authority to approve pre and post-deployment approvals to the cloud hub.

Step 11: Now the application has been deployed to the cloud hub. Please note since I don’t have two environments to deploy, I just used the environment (Sandbox) and credentials in those two stages (Dev and UAT), I just changed the application name alone in variable groups for two environments.

Cloud hub deployment, should look like this

Conclusion:

With the knowledge from this article under your belt, you have learned how to create a CI/CD Pipeline using Azure DevOps and deploy mule application to cloud hub. Understanding the practice of continuous integration will make you a valuable member of any team.

Author: Vinodh Bharathi
ESB professional with 8+ years experience in IBM Integration Bus (IIB v10), IBM APP connect (ACE) and Mulesoft in designing and developing of Middleware based applications in Banking, finance and Medical domains

Originally published at https://saamaanalytics.com on May 14, 2021.

--

--