DEV Community

Bruno Souza
Bruno Souza

Posted on

Deploying MuleSoft Application to Cloudhub 2.0 using Azure DevOps - Part 1

This article we will talk about how to deploy a MuleSoft Application using Azure DevOps as a CI/CD tool with yaml file as scripts to reuse in any projects.

We will use Azure Repos as git repository to pipeline scripts and the MuleSoft application.

I'll split the full process in 2 articles, this article we will explore the deploy to develop environment and the next article we will explore the deploy to production environment.

Azure DevOps Project

Create a new Project in Azure DevOps with mulesoft-projects name

Importing Script Pipeline

After create your project in Azure DevOps, we need import the devops-scripts to azure repos.

Ps. Use the devops-scripts as repo name with main branch.

Azure DevOps Configuration

Now we will create the variables, you can navigate to Pipeline menu in your project and click on Library.

Azure DevOps

Variable Groups

Variable Groups are frequently used to store values that are desirable to make available across the pipelines. Additionally, they can be used to store secrets and credentials that are going to be needed into our build and release pipelines. We are going to create the following variable groups:

  • anypoint-platform-variables :

    • AnypointClientId - Specifies the Connected App clientID value
    • AnypointClientSecret - Specifies the Connected App secret key.
  • anypoint-platform-<ENVIRONMENT>-variables :

    • chEnv - Specifies the Cloudhub Environment Name
    • muleEnv - Specifies the Mule Environment used in your project
  • <APPLICATION NAME> :

    • encryptKey - encrypt key for production
    • encryptKeyNonProd - encrypt key for non-production

This variable is used to add common passwords used in all application, if you have to use dynamic properties, we'll talk about in another article how to add dynamic properties with parent-pom.

Azure DevOps

Connected App

Click here to learn how to create a Connected App at Anypoint Platform.

This is the scopes you need add to deploy process

Runtime Manager
Create Applications
Read Applications
General
View Environment
View Organization
Exchange
Exchange Contributor
Exchange Viewer

Secure Files

Secure Files can be used to encrypt valuable resources that will be needed during the build and release pipelines.

The Maven settings.xml file containing:

  • MuleSoft Enterprise Repository Nexus Credentials.
  • Connected APP to deploy

In devops-script repository has a template into /common folder

Add the settings.xml in secure file to be use in deploy process.

Azure DevOps

Deployment Steps

The pipeline will be triggered when you do a commit in develop branch, we're testing the code, creating an Artifact to use in Production deploy and do the deploy to develop environment.

The Release Pipeline is a manual process to deploy in production environment using the artifact created in develop steps with approvers.

The diagram below illustrates the concept:

Azure DevOps

Scripts

We have 2 main scripts in our process:

  • azure-pipelines.yml
  • mulesoft-jobs.yml

The script azure-pipeline.yml is in raw folder from MuleSoft application and contains the minimal configuration to start the process.

The script mulesoft-jobs.yml is in devops-scripts repository, is the common script with the steps of the deploy process.

MuleSoft Application

To this example you will import this example.

I project you have 2 important files:

  • azure-pipelines.yml
  • pom.xml

Azure-pipelines.yml

name: $(Date:yyyyMMdd).$(Rev:r)
resources:
  repositories:
  - repository: devops-scripts
    type: git
    name: mulesoft-projects/devops-scripts
    ref: refs/heads/main

trigger:
- develop
- release-\*

stages:
- template: mulesoft-jobs.yml@devops-scripts
Enter fullscreen mode Exit fullscreen mode

Name : This is the code you see every time you run the pipeline
Resources/Repositories : The repository used to call the template in stage
Trigger : the branches that will trigger
Stages/Template : main script yaml from process

Pom.xml

The configuration to deploy in Cloudhub

<cloudhub2Deployment>
…
</cloudhub2Deployment>
Enter fullscreen mode Exit fullscreen mode

The config to deploy in Anypoint Exchange

<distributionManagement>
…
</distributionManagement>
Enter fullscreen mode Exit fullscreen mode

If you need more details about deploy config using maven, click here

Creating Pipeline to your Application

Go to Pipelines and click in New Pipeline

Azure DevOps

Choose Azure Repos Git (YAML)

Azure DevOps

Choose the Mule Application Repository (hello-world)

Azure DevOps

You can see the azure-pipelines.yml, Click in Save

Azure DevOps

Now you can Run the Pipeline (use develop branch, the script has a rule to only deploy develop branch, to production we will use the Release Pipelines)

Azure DevOps

Azure DevOps

Now click in your pipeline to follow the steps and in your first time you need permit the access to Devops-scripts repository and variable group.

Azure DevOps

Azure DevOps

Config Slack/Teams to Azure DevOps

The notification doesn't in scripts, you need config your tools using the links below.

Slack
Microsoft Teams

Conclusion

This article does not have the complete deployment process, but the idea is to show how to deploy using the yaml file to reuse in other projects. I tried to use a simple idea using yaml scripts and I believe with this you can study and learn more.

In yaml script you will see a maven setup script, this script is due a MuleSoft issue with maven 3.9 in this moment (feb-2023).

Reference:
gitflow-workflow
Azure-DevOps

Code Source
devops-scripts
MuleSoft hello-world

Top comments (1)

Collapse
 
aleksandroribeiroct profile image
Aleksandro Ribeiro CT

Can I add variables for user and password in settings.xml and retrieve this information from Azure DevOps Variables Groups?