Apisero is now part of NTT DATA - Learn more.

Search
Close this search box.

Azure DevOps CI/CD With Mule Application And CloudHub

Author: Ashish Jha

Introduction

This document aims to address the use case of integrating a MuleSoft application, MuleSoft cloudhub and Azure CI/CD. The steps needed to create a CI/CD pipeline for deploying a MuleSoft application to cloudhub, using Azure DevOps.

What is CI/CD

CI/CD is the acronym for Continuous Integration and Continuous Deployment/Continuous Delivery.

Continuous Integration refers to the practice where developers work on different git branches and  constantly merge the changed code to a central repository.

The code is merged to a working branch, where the code is built and tested using the automated workflows.This makes sure that all the merged codes are together functioning properly and are well tested.

In Continuous Deployment the merged and tested code from the central repository is released to the production environment using an automated process and is made available to users/customers for use.

What is Azure DevOps?

Azure DevOps is one of the leading tools that can automate CI/CD processes. Refer to the flow-diagram below, here we have to upload the code from our local system to a central repository like GitHub repository or Azure repository, which is connected to the Azure CI/CD pipeline where the automated testing is done and the project is built and then deployed to the target environment. In our case we have deployed the application to the CloudHub

Steps to create the CI/CD pipeline
Prerequisites
  1. Knowledge of Github or Azure would be required, we need the GitHub or Azure repository.
  2. Git should be installed in the system.
  3. Anypoint Platform account
  4. Anypoint Studio
  5. Azure DevOps account
Setting the Mule application

Open the project explorer and go to the pom.xml file.

Add the  deployment configuration in the Mule-Maven-Plugin. Refer the below screenshot:

<configuration>

 <cloudHubDeployment>

 <uri>https://anypoint.mulesoft.com</uri>

 <server>${server}</server>

 <muleVersion>${app.runtime}</muleVersion>

<applicationName>${app.name}</applicationName>

 <workers>${worker}</workers>

<workerType>${workerType}</workerType>

<environment>${environment}</environment>

 <objectStoreV2>true</objectStoreV2>

 </cloudHubDeployment>

 </configuration>

Important:

  • <objectStorev2> should be set to “true”.
  • <uri> should be set to “https://anypoint.mulesoft.com”.
Push the project to the GitHub repository

Step 1: Sign in  to your GitHub account and create a repository.

Step 2:  Now go to the project directory in your system and open the Command Prompt there and initialize the git repository using command : git init

Step 3: Add the files to the git repository using the command: git add .

Step 4: Commit the changes to the git repository using the command: 

git commit -m “Initial commit”.

Step 5: Change the branch to main with command: git branch -M main

Step 6: Add remote origin with command git remote add origin https://github.com/<your GitHub username>/<your repository name>.git

Eg:  git remote add origin http://github.com/API1619/azure-pipeline-demo.git

Step 7: Push the project to the github repository using the command: git push -u origin main

Refresh you git repository and check the uploaded project

Step 8: Create a “dev” branch in the git repository.

Setting up the Azure CI/CD Pipeline

Step 1: Sign in to your Azure DevOps account.

You can create the account at https://azure.microsoft.com/

Step 2: Create a new project.

Give a suitable name and description to the project.

Step 3: Click on Pipelines from the left side menu .

Step 4: Click on the “Create Pipeline” button.

Step 5: From the new page that opens, select GitHub.

For the first time Azure will require you to give access to your GitHub account. In that case proceed and give access.

Step 6: Now select the repository that you have created in the GitHub.

Click on “Approve and Install”.

Step 7: Select your account.

Step 8: On the next screen that appears select “Maven”.

Step 9: Now click on the “Variables” button and then on “New Variable” button.

Step 10: Here provide the name and value of the fields  that we defined in  deployment configuration in the pom.xml file.

Add all names and values of all the fields and click the save button.

  • Application name should be unique.
  • App runtime should be the same as that of used in the project.
  • Environment can be changed according to the need.

Step 11:  Click on the “Save and Run” button and then click the “Save” button.

Step 12: Provide a suitable name and click on the “Save” button.

Click on the “Pipelines” from the left side menu and you can see that the pipeline has been created.

Prepare the azure-pipelines.yml file

Step 1: Copy and paste the contents of the “azure-pipelines.yaml” file from the link given below:

https://github.com/API1619/azure-pipeline-demo/blob/dev/azure-pipelines.yml

*Important: 

  • File name should be “azure-pipelines.yml”.

            Here we have set the trigger to work when there is any change to the “dev” branch.

  •   

  “azure-pipelines.yml” and “pom.xml” are excluded from the trigger which means any change in these two files will not trigger the job.]

  • Cache is done so that it will not download Maven dependencies every time the job is triggered. This helps to save time while deploying.

Step 2: Save the “azure-pipelines.yml” file and put it in the root directory of the project.

*Make sure that the “azure-pipelines.yml” file is in the root directory of the project.

Step 3: Create the “settings.xml” file.

<settings>

<servers>

<server>

<id>Anypoint</id>

<username>{Place your Anypoint Platform’s Username here}</username>

<password>{Place your Anypoint Platform’s Password here}</password>

</server>

</servers>

</settings>

Deploying application to the CloudHub

Step 1: Go to the project directory and open command prompt and change the git branch from “main” to dev” using the command: “git branch -M dev“

Step 2: Add the files to git using the command: “git add .”

Step 3: Now commit the changes using the command: git commit -m “Yaml file added”

Step 4: Push the changes to the repository using the command: “git push -u origin dev”

Step 5: Go to “Library” in Azure Pipelines

Step 6: Click on the “Variable Group” button.

Step 7: Give the Variable group name as “Build-Variable-Group” and then click the “+Add” button.

Step 8: Now give the name as “settingsxml.secureFilePath” and value as “settings.xml”, and click save.

Step 9: Click on “Library” from the left side menu and then click on “Secure files”.

Step 10: Click on the “+Secure file” button.

Step 11: Browse the “settings.xml” file that we created and click “OK”.

Trigger the Job

Step 1: Go to your application and do some minor changes to mock the code change and save the project.

Step 2: Add the files to the GitHub repository using the command: “git add .”

Step 3: Commit the change using the command: git commit -m “<your message>”

Step 4: Push the change to the GitHub repository using the command: “git push -u origin dev”

Step 5: Go to Azure DevOps and click on “Pipelines”, you can see that the pipeline has started.

Step 6: Click on the pipeline that has started and on the next screen click on the “Stages” icon as indicated in the screenshot below.

Step 7: For the first time to run the job we need to give permission. Click on “View”.

Step 8: Click on the “Permit” button.

Step 10: Click on the “Permit” button to give permission.

*IMPORTANT

  • If after Step 10 you get an error stating “No hosted parallelism has been purchased or granted.. Then fill the form provided with the error to request for free parallelism. This may take 2-3 days. 
  • After getting the free parallelism, do some minor changes again in the code to mock a code change and then push the code to the GitHub repository. Check the pipeline the job would have started.
  • After the job is finished, open your Anypoint Platform and go to “Runtime Manager” and you will find your application deployed there.
  • Click on the application to check the details.

Step 11: Watch the logs as the job gets built and deployed.

Once the Job is successfully finished go to your Anypoint Platform and in Runtime manager click on your deployed application and check the details.

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.