Deploying Mule Application Using Azure DevOps

By May 14, 2021 May 25th, 2021 Blogs
Deploying Mule Application Using Azure DevOps Blog

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.

Deploying Mule Application Using Azure DevOps - 1Open command prompt in this location and do GIT initialization, here are the commands to be used to push the code

  • Create a new and empty Git repository in the current working directory using the below command. The command only creates the .git repository folder.

    a.git init
     
  • Add the files to your newly created local repository. This stages them for the first commit. 

    git add .

  • Commit the files from your local repository. 

    git commit -m “First commit”

  • Add the URL of the remote repository where your local repository will be pushed. 

    git remote add origin <remote repository URL>

  • Push the changes to GitHub if there is a remote branch called master (or main if that’s what you’re using) 

    git push origin master

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.

Deploying Mule Application Using Azure DevOps - 2
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,

Deploying Mule Application Using Azure DevOps - 3
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. 

Deploying Mule Application Using Azure DevOps - 4
Click
Clone and we will use the clone URL for linking the local GitHub repository to the Azure repository.

Deploying Mule Application Using Azure DevOps - 5

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

Deploying Mule Application Using Azure DevOps - 6

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.

Deploying Mule Application Using Azure DevOps - 7

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

Deploying Mule Application Using Azure DevOps - 8

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

Deploying Mule Application Using Azure DevOps - 9

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.

Deploying Mule Application Using Azure DevOps - 10

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 2nd environment (UAT env) too. 

Dev env variables:

Deploying Mule Application Using Azure DevOps - 11

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

Deploying Mule Application Using Azure DevOps - 12

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 

Deploying Mule Application Using Azure DevOps - 13

Cache settings highlighted below

Deploying Mule Application Using Azure DevOps - 14

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

Deploying Mule Application Using Azure DevOps - 15Add Copy files job to tasks by clicking + symbol,

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

Deploying Mule Application Using Azure DevOps - 16

Publish the artifacts job, as shown below,

Deploying Mule Application Using Azure DevOps - 17

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,

Deploying Mule Application Using Azure DevOps - 18Note: 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

Deploying Mule Application Using Azure DevOps - 19

After clicking the new, Select Azure App service deployment 

 

Deploying Mule Application Using Azure DevOps - 20

This how it should look now.

Deploying Mule Application Using Azure DevOps - 21Step 6:  

  1. We will configure the create pipeline name in the release stage highlighted below,

Deploying Mule Application Using Azure DevOps - 22Select the create pipeline name correctly from which you want to download artifact,

Deploying Mule Application Using Azure DevOps - 23Enable the continuous deployment trigger by clicking the small lighting symbol below,

  1. After setting the pipeline Enable the continuous deployment trigger by clicking the small lighting symbol below in the release stage.

Deploying Mule Application Using Azure DevOps - 24Step 7: Now we have to add environments in the staging layer. Click +Add

Deploying Mule Application Using Azure DevOps - 25Step 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.

Deploying Mule Application Using Azure DevOps - 26Now we are going to link Dev env variable group to the Dev stage. For the select Dev env variable group and you will see the below pop up. In that select stages and select the Dev environment stage. 

Deploying Mule Application Using Azure DevOps - 27For deployment, the Dev stage will use the credentials and environment details to deploy the code to the cloud hub. Link the UAT env variable group to the UAT stage using the same steps explained above.

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.

Deploying Mule Application Using Azure DevOps - 28If you see the command I have not hardcoded the environment details, instead, I am fetching it from variables that we linked to each stage.

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. 

Deploying Mule Application Using Azure DevOps - 29They will receive mail for the build, pre and post-deployment approvals.

Deploying Mule Application Using Azure DevOps - 30Step 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

Deploying Mule Application Using Azure DevOps - 31Conclusion: 

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.

Vinodh Bharathi

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