Azure Pipelines is a cloud service that you can use to automatically build and test your code project and make it available to other users. It works with just about any language or project type.
Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to constantly and consistently test and build your code and ship it to any target.
In this codelab, you're going to build an Azure pipeline to automate the continuous integration and continuous delivery.
You can create an instance of each system in Cloud Services
For this Lab we are going to use the Hello World example that is an example that is in Exchange. Please feel free to use this lab with any other project and import it into Studio.
At the end you should see something similar to this:
This project may have old dependencies, what we are going to do now is to update them.
First login to Azure DevOps Services
Once you login, you will see the following screen
Now you are ready to create a new project
We created the Organization, now we need to create a new project.
This is going to be part of the git url. I would recommend to not use spaces. Also notice that we decided to make this project private.
Once you create the project, you will see the following screen
Be careful when you invite a user. By default they are invited with the stakeholder role. They won't have access to any repo unless you change her profile. More information can be found here. You can also go to the appendix to learn how to change the profile.
This step is needed if you login to Azure using a corporate user.
Take note of the URL, user and password. You are going to need it in the next section.
Great!!! In the next section we are going to configure the Studio Project to use this repo
In this section we are going to initialize our mule project to the Git repository. We will be using EGit that comes with Studio. But feel free to choose any tool you want.
Now that we have everything in our local repository. We want to push the changes in the remote one.
A complete guide on how to use Git with Studio can be foundhere
To do the deployment we are going to use the maven plugin. Information about the Mule Maven Plugin can be foundhere.
In the next section we will configure the pom.xml file.
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
</configuration>
</plugin>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri> (1)
<muleVersion>4.3.0</muleVersion> (2)
<username>${anypoint.username}</username> (3)
<password>${anypoint.password}</password> (4)
<environment>${cloudhub.environment}</environment> (5)
<applicationName>${cloudhub.app}</applicationName> (6)
<workerType>Micro</workerType> (7)
</cloudHubDeployment>
These are all parameters that can be hardcoded inside the POM or injected when you do the deployment. The description of each parameter can be found here:
If you want to test it, you can deploy manually from your computer. Try to execute the following command:
mvn -V -e -DskipTests deploy -DmuleDeploy \ -Danypoint.username=<username> -Danypoint.password=<password> \ -Dcloudhub.app=dev-hello-world -Dcloudhub.environment=Sandbox
Azure doesn't have a global settings.xml for maven. Everything needs to be in the POM. That's why we are going to add some repositories to the file.
<repository>
<id>mulesoft-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
<layout>default</layout>
</repository>
In this section, we are going to create an Azure pipeline to automate the deployment to cloudhub.
Azure provides access to the public repositories by default, but if you need access to the Enterprise Repository, you need to follow these steps.
Now we need to update the pom.xml file. We will add some libraries needed by the MUnit plugin to run.
<pluginRepositories>
<pluginRepository>
<id>mulesoft-release</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>http://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>mule-public</id>
<url>https://repository.mulesoft.org/nexus/content/repositories/releases</url>
</pluginRepository>
<pluginRepository>
<id>MuleRepository</id>
<name>MuleRepository</name>
<url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>mulesoft-public-plugin</id>
<name>MuleSoft Public Repository</name>
<url>https://repository.mulesoft.org/nexus/content/repositories/public/</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
Great, you configure the Mulesoft Enterprise Repository in Azure.
In this section we are going to add two more steps to the pipeline.
The first step will build the package. The second one will test the application and the third one will deploy the application to cloudhub.
We need to update the azure-pipelines.yml. This file is in the repo now. You can do a git pull and edit the file in Studio.
In this lab we are going to do in Azure
This is the step where the jar is going to be created. This step is created when you create a new pipeline. We are going to make some changes to this step.
- task: Maven@3
displayName: Build
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
- task: Maven@3
displayName: Build
inputs:
options: '-DskipTests'
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'package'
- task: Maven@3
displayName: Build
inputs:
options: '-DskipTests'
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
goals: 'package'
In this step we are going to run the MUnit tests. To execute this step, you need a Nexus user to access the Enterprise Mulesoft Repository. If you don't have one, you can check here to see how to request one. If you aren't a customer and you can't get these credentials, you can skip this step and move to the next one.
As I mentioned before, we are required to configure a private repository. So first go to the appendix to add the Mulesoft Enterprise Repository credentials to the project.
Azure doesn't have a global settings.xml where you can configure all the repositories, profiles and credentials. Instead it has a step where you can add the server credentials into the settings.xml installed in the image. That's why we are going to create a Maven Authentication step to add the credentials we created in the appendix.
goals: 'package'
line.The step should look like this:
Here we are going to create the maven test task.
Leave the rest as default. Press add when finished.
At the end you should see something like this
The last step will deploy the package into Cloudhub.
In the pom.xml file we declared 4 variables.
In Azure, we can declare variables to be used in the pipeline. We are going to define one variable to be replaced in the pipeline we deploy.
Once finished you will see all the variables listed. Press Save to Continue.
We declared the variables, now it's time to create the deployment task.
- task: Maven@3
displayName: Deploy
inputs:
mavenPomFile: 'pom.xml'
goals: 'deploy'
options: '-DskipTests -DmuleDeploy -Danypoint.username=$(mule.username)-Danypoint.password=$(mule.password) -Dcloudhub.environment=$(mule.environment)-Dcloudhub.app=$(mule.app)'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
At the end you should see something like this
We are going to save the pipeline and this is going to be a new commit.
Congratulations!!! You have the Yaml file with the pipeline.
We created the pipeline, in this section we are going to run it
After you press run you will see a screen showing the pipeline information.
When you press the link a live window will appear. It shows the steps and logs of the current step running. Let's wait the process to finish to continue.
By running the pipeline, we:
In the next section we are going to automate the build process, so each time you push a change, the pipeline starts automatically.
To automate the process is really simple. We just need to update the trigger section in the pipeline file.
trigger:
batch: true
branches:
include:
- releases/*
With this command all the branches are going to be triggered automatically. Also we are setting the batch property to true, If you have many team members uploading changes often, you may want to reduce the number of runs you start. If you set batch to true, when a pipeline is running, the system waits until the run is completed, then starts another run with all changes that have not yet been built.
If you want to get more information around this subject you can check here
Now we are going to do a change in the project, push the changes and see how the build process starts automatically
In this codelab, you learned how to implement a CICD solution using Azure Pipeline. Please take a look at the Resources to learn more about Azure and the Mule Maven Plugin