Professional Documents
Culture Documents
How-To Create A Cicd Pipeline Using Azure Devops v1
How-To Create A Cicd Pipeline Using Azure Devops v1
DevOps
• Introduction
• Scope
• Audience
• Modules/Plugin Versions
• How-To
• Azure DevOps Configuration
• Variable Groups
• Process
• Secure Files
• Process
• Build Pipeline Configuration
• Build Pipeline (from develop branch)
• Process
• Build Pipeline (from master branch)
• Process
• Maven Release Plugin Configuration
• Running the master branch build pipeline
• Release pipeline configuration
• Executing the Release Pipeline
1 Introduction
The purpose of the following article is to describe the step by step process for implementing a basic CI/CD
Pipeline using the Mule Maven Plugin as well as the Maven Release Plugin in Azure DevOps.
Process overview:
On merge/commit over the "develop" branch, a job is executed and the generated
artifact is deployed in DEV environment.
On merge/commit over the "master" branch, a job is executed for releasing a new version
of the application. The generated artifact is deployed to either Anypoint Exchange and
the Azure Binary Repository (not a SNAPSHOT). The generated artifact can then be
promoted to TEST and PROD environment.
The instructions in this article might not work on different versions of the product.
If there are issues with the approach in the article, please provide feedback. If you experience any
issues with Microsoft Azure DevOps
or any non-MuleSoft related products, please refer to the relevant vendor's documentation or
customer support.
The scope / complexity of a CI/CD Pipeline might vary depending on several factors. This should
not be taken as a silver bullet. The main goal is to show different aspects that need to be
considered and serve as a guideline for Azure DevOps configuration.
2 Scope
CI/CD Pipeline configuration using Azure DevOps.
3 Audience
• Application / Operator Admin
• C4E Architects / Architects
• C4E Core Developers / Developers
4 Modules/Plugin Versions
As a reference, here is the list of Modules/Plugins Versions used for writing the article.
Mule Runtime 4.X
Maven Release Plugin2.5.3
Mule Maven Plugin 3.3.5
5 How-To
Process
1. Log into Azure DevOps, select your Project and go to Pipelines → Library:
2. Create a new Variable Group, assign a name/description and add the required variables as
follows:
Note: Using the "Change variable type to secret" is very useful for sensitive data.
• GIT Repository Credentials (this is going to be used by the Maven Release Plugin).
• A Fake pom.xml file that is going to be used during the release pipeline to deploy the
generated artifact. This consists of a typical Maven pom.xml file for Mule Applications
containing the Mule Maven Plugin configuration of your deployment model. E.g: CloudHub
Deployment Reference.
pom.xml
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>mulesoft-releases</id>
<name>mulesoft release repository</name>
<layout>default</layout>
<url>https://repository.mulesoft.org/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
Process
1. Go to Pipeline → Library → Secure files.
2. Click the Add Secure File, and browse into your file systems the items that need to be
uploaded.
Process
1. Log into Azure DevOps, select your Project and go to Pipelines → Pipelines → New
pipeline.
3. Select a source (e.g.: Azure Repos Git), the project / repository and finally set the default
branch to develop based on the previous explanation. Once finished, click the continue
button.
4. Among the available templates choose Maven and click the Apply button.
5. Edit pipeline name and delete the Copy Files and Publish Artifact tasks. After saving your
changes the pipeline should looks as follows.
6. Click the Add task button, search for "Download secure file" and click the Add button.
7. Drag the task to the top of the pipeline and rename as "Download settings.xml". Finally,
select the "settings.xml" file from the drop-down list.
8. Click the Add task button for adding other two Maven tasks. You should have a total of
three; one for each Maven build lifecycle phase (Test, Package and Deploy).
9. Maven Test Phase Configuration.
a. Select the first Maven Task and rename as Test.
b. Set the goal to:
clean test
c. In the options set a reference to the downloaded settings.xml file from the Azure
Library:
-s $(Agent.TempDirectory)/settings.xml
-s $(Agent.TempDirectory)/settings.xml
-s $(Agent.TempDirectory)/settings.xml -Danypoint.account.username=$
(MuleDeployerUsername) -Danypoint.account.password=$(MuleDeployerPassword)
-Dbusiness.group.id=$(BusinessGroupId) -Danypoint.platform.client.id=$(ClientId)
-Danypoint.platform.client.secret=$(ClientSecret) -Dcloudhub.application.name=$
(Environment)-contacts-sapi-v1 -Denvironment=$(Environment)
Note: These parameters will depend on your deployment model. This example is
based on the Deploy to CloudHub configuration. For further information please
refer to Mule Maven Plugin configuration.
Notice that the parameters configured in this step belongs to the ones added into
the Variable Groups as part of the initial configuration.
d. Uncheck Publish to Azure Pipelines and click the Save & queue → Save button.
12. (OPTIONAL) In order to prevent executions of this pipeline from a different branch (e.g.:
master), on each of the configured tasks (Download settings.xml, Test, Package and
Deploy) you can add the following configuration so that the task executes only when the
previous task finish successfully and the pipeline has been triggered from the develop
branch:
a. Expand Control Options.
b. Set Run this task to Custom conditions.
c. Set Custom condition to:
d. Repeat for the Test, Package and Deploy Dev Maven tasks.
b. Link the following variable groups: Anypoint Platform DEV Variables and Azure
DevOps Mule Deployer which contains the required variables for the Development
deployment.
Process
1. Log into Azure DevOps, select your Project and go to Pipelines → Pipelines → New
pipeline.
2. Switch to the Classic Editor view.
3. Select a source (e.g.: Azure Repos Git), the project / repository and finally set the default
branch to master based on the previous explanation. Once finished, click the
continue button.
4. Among the available templates choose Maven and click the Apply button.
5. Edit pipeline name.
6. Click the Add task button, search for "Download secure file" and click the Add button.
7. Drag the task to the top of the pipeline and rename as "Download settings.xml". Finally,
select the "settings.xml" file from the drop-down list.
8. Click the Add task button for adding other three Maven tasks. You should have a total of
four; one for each Maven task (Test, Package, Release Prepare and Release Perform).
9. Configure the Maven Test Phase (as you did in the previous pipeline).
10. Configure the Maven Package Phase (as you did in the previous pipeline).
11. Set GIT identity. As the Maven Release Plugin runs SCM commands in the background (e.g:
to update artifact version in the POM file, creating a tag, etc); we are going to use a script
to enable the use of GIT commands.
a. Click the Add task button, search for Bash script and place immediate after the
Maven Package task.
release:prepare --batch-mode
release:perform
14. (OPTIONAL) In order to prevent executions of this pipeline from a different branch (e.g.:
develop), on each of the configured tasks you can add the following configuration so that
the task executes only when the previous task finish successfully and the pipeline has been
triggered from the master branch:
a. Expand Control Options.
b. Set Run this task to Custom conditions.
c. Set Custom condition to:
Ref.: Specify Conditions
<groupId>ORGANIZATION_ID</groupId>
<artifactId>MY-APP-IMPL</artifactId>
2. Add the Maven facade as a repository in the distribution management section of the
project's POM file (the repository credentials needs to be configured in the settings.xml
file uploaded into the Azure DevOps Library):
<distributionManagement>
<repository>
<id>MuleExchangeRepository</id>
<name>MuleExchangeRepository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/
ORGANIZATION_ID/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>
3. Update the POM properties with the SCM ID (the SCM credentials need to also be
configured in the settings.xml file that was uploaded into the Azure DevOps Library)
and the Maven Release Plugin Version (e.g.: 2.5.3):
<properties>
<!-- other properties here -->
<maven.release.plugin.version>2.5.3</maven.release.plugin.version>
<project.scm.id>AZURE_GIT_REPO_ID</project.scm.id>
</properties>
4. Add the reference to the project SCM repository (e.g.: Azure GIT repo):
<scm>
<connection>scm:git:GIT_REPO_URL</connection>
<developerConnection>scm:git:GIT_REPO_URL</developerConnection>
<tag>HEAD</tag>
</scm>
5. Add the Maven Release Plugin configuration to the project's POM file:
<build>
<plugins>
<!-- other plugins -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven.release.plugin.version}</version>
</plugin>
</plugins>
</build>
3. Once the build execution finishes successfully, go to Repos → Commit and select the
master branch. Check that:
a. A tag has been created for the released version.
b. The version in the pom.xml file has been increased for the next release.
4. Log into Anypoint Platform and go to Anypoint Exchange. Check that the build artifact
has been successfully uploaded into Exchange. In order to do that, you need to update the
following URL with the ORGANIZATION_ID and ARTIFACT_ID values in the pom.xml file.
https://anypoint.mulesoft.com/exchange/ORGANIZATION_ID/ARTIFACT_ID/
1. Log into Azure DevOps, go to the Releases menu and click New → New release pipeline.
6. Nest step is configuring a trigger for the pipeline. Click on the Continuos deployment
trigger button and enable the trigger in order to create a new release every time a new
build is available.
7. Finally, we need to add the required Maven tasks in order to deploy the Mule Application
into TEST environment.
a. Edit the pre-deployment condition and set the trigger to Manual only.
b. Click on the 1 job, 0 task link into the stage activity of your pre-prod environment
(e.g.: TEST).
c. Click on the Add task button and add a Download secure file task.
d. Set the Display name to Download pom.xml file.
e. Select the pom.xml file from the dropdown list. This is the secured file that was
previously uploaded to Azure Library.
f. Add a bash script task to the pipeline. This is needed to pick the artifact that was
generated in the build pipeline triggered from master branch which is stored into
the Azure staging directory.
g. Set the Display name to Find artifact.
h. Set the script type to inline.
i. Copy and paste the following lines.
cd $(Release.PrimaryArtifactSourceAlias)/drop/target
ls -la
artifact=$(ls | grep *.jar)
echo "##vso[task.setvariable variable=ARTIFACT;]$artifact"
$(Agent.TempDirectory)/pom.xml
mule:deploy
n. Uncheck the Publish to Azure Pipelines box and click the Save button.
o. Select Variables → Variable groups → Link variable group and link Azure DevOps
Mule Deployer and Anypoint Platform TEST Variables to the current stage. E.g.:
TEST
Click the Save button and go back to Pipeline tab.
8. The stage for your production environment can be cloned from the previous one. For the
purpose of the example I've set a Manual only trigger.
9. Click on the View stage tasks link to edit the Variable groups (in this case for the PROD
environment).
5. Verify the artifact has successfully deployed into the specific environment.
6. Finally, you can move forward with the deployment into PROD.