DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Deploying MuleSoft Using Azure DevOps
  • Set Up a CI/CD Pipeline for An Angular 7 Application From Azure DevOps to AWS S3 - Part 2
  • Zero to Hero on Kubernetes With Devtron
  • Testing Serverless Functions

Trending

  • Solid Testing Strategies for Salesforce Releases
  • The Role of Retrieval Augmented Generation (RAG) in Development of AI-Infused Enterprise Applications
  • Grafana Loki Fundamentals and Architecture
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Mule 4 Continuous Integration Using Azure DevOps

Mule 4 Continuous Integration Using Azure DevOps

An integration engineer gives a tutorial on creating an Azure project and integrating different branches together using Mule 4.

By 
Edgar Moran user avatar
Edgar Moran
·
Jan. 11, 21 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
7.4K Views

Join the DZone community and get the full member experience.

Join For Free

Once we started developing applications in MuleSoft and storing our code in source control platforms like GitHub, Bitbucket, GitLab, or Azure, just to mention the most common ones, we needed to look into automating the process to deploy our applications either to CloudHub or an on-premise server.

In this post, I will try to explain how a MuleSoft application can be automatically deployed into CloudHub or an on-premise server from Azure DevOps as our main CI platform and source control platform.

Create a Project in Azure

The first step is to setup our project in Azure DevOps. For this, you need a Microsoft account, which you can set up here: https://dev.azure.com/.

Then we can create a new project, provide a name and a description, as well as set the privacy; by default, it comes set as "private."

image-2.png

Once this is created, we can go into the main page and locate the "Repos" section. Once we see the page, we can use the information to send our code directly from our local environment.

image.png

But just before actually pushing any code, we can create a pretty simple endpoint that we can hit later to verify everything is working. So, in Anypoint, create a pretty simple RAML definition:

YAML
 




x
25


 
1
#%RAML 1.0
2
title: Sample API
3

          
4
/persons:
5
  get:
6
    responses:
7
      200:
8
        body:
9
          application/json:
10
            example: |
11
              [{
12
              "id": 1,
13
              "name": "Edgar Moran",
14
              "username": "emoran",
15
              "email": "yucel.moran@some.test",
16
              "address": {
17
                "street": "Kulas Light",
18
                "suite": "Apt. 556",
19
                "city": "Gwenborough",
20
                "zipcode": "92998-3874",
21
                "geo": {
22
                  "lat": "-37.3159",
23
                  "lng": "81.1496"
24
                }
25
                }}]


Then we can generate the flows in our project: right-click on the RAML file > Mule > Generate Flows from Local REST API.


image-1.png

Then, once we have our flow generated, we can proceed to create our test.yaml file in order to identify any value we want to attach to our environment.

It will look just like this:

YAML
 




xxxxxxxxxx
1


 
1
http:
2
  port: "8081"
3
environment: "[TEST]"


Then we can create a global.xml configuration file in which to keep our configurations. We can add a Configuration Property config as shown below:

image-2.png

Then we can create a Global property, in this case called env, which will allow us to know in which environment we are working.

image-3.png


I know, it's a lot, but let's try to do it right. Just before our final check to verify everything is working, let's add an environment variable called env in our Run Configuration.

image-5.png
image-4.png

Then let's run the project. If all went okay, we'll see our project deployed!

image-6.png

So if it's all good, then we can start pushing our first version of this working code into our Azure repo. Let's do that next.

Generating a Personal Access Token

Let's go back into the Azure DevOps main project page:

image-7.png

And then let's create a personal access token:

image-9.png

Click on 'Create a new token.' You'll see a bunch of options; select the actions and permissions you consider best depending of your needs.

image-10.png

Once created, you'll have a new token which becomes your project password, so keep it safe!

Now we can push our code. If the terminal asks you for a password, use the token you just generated and your code should be on the master branch:

image-11.png

All right, so we have our code already in Azure. Now, let's create a new branch for our repository. Let's call it test, based on the master, and let's create a developer branch called emoran.

It's important to mention that during this example we will review the build on the emoran branch and we will deploy to CloudHub in the test branch.

Create an Artifact

Before we create our pipeline, we need to make sure we have the right information in our settings.xml and pom.xml files. This artifact will allow us to get the Distribution Management piece we need to set in our project. For this, we will need to go into our main project page and locate the artifact option on the left, then we need to click on "Connect to feed." Next, select Maven and it will show the information we need to put into our settings.xml and pom.xml files.

image-14.png

Preparing Our settings.xml and pom.xml Files

Now, the next task will be to prepare our files in order to make sure we can build and deploy our application into CloudHub.

Here's how my settings file looks:

XML
 




xxxxxxxxxx
1
49


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
3
   <servers>
4
      <server>
5
         <id>yucelmoran-azure-pipeline</id>
6
         <username>yucelmorans</username>
7
         <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
8
         <!-- The generated token expires on or before 17/11/2019 -->
9
         <password>${azure.password}</password>
10
      </server>
11
      <server>
12
         <id>MuleRepository</id>
13
         <username>${nexus.username}</username>
14
         <password>${nexus.password}</password>
15
      </server>
16
   </servers>
17
   <profiles>
18
      <profile>
19
         <id>Mule</id>
20
         <activation>
21
            <activeByDefault>true</activeByDefault>
22
         </activation>
23
         <repositories>
24
            <repository>
25
               <id>yucelmoran-azure-pipeline</id>
26
               <url>https://pkgs.dev.azure.com/yucelmorans/yucelmoran-azure-pipeline/_packaging/yucelmoran-azure-pipeline/maven/v1</url>
27
               <releases>
28
                  <enabled>true</enabled>
29
               </releases>
30
               <snapshots>
31
                  <enabled>true</enabled>
32
               </snapshots>
33
            </repository>
34
            <repository>
35
               <id>MuleRepository</id>
36
               <name>MuleRepository</name>
37
               <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
38
               <layout>default</layout>
39
               <releases>
40
                  <enabled>true</enabled>
41
               </releases>
42
               <snapshots>
43
                  <enabled>true</enabled>
44
               </snapshots>
45
            </repository>
46
         </repositories>
47
      </profile>
48
   </profiles>
49
</settings>


And here's the pom.xml file: 

XML
 




xxxxxxxxxx
1
183


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
   <modelVersion>4.0.0</modelVersion>
4
   <groupId>com.emoran</groupId>
5
   <artifactId>yucelmoran-azure-pipeline</artifactId>
6
   <version>1.0.0-SNAPSHOT</version>
7
   <packaging>mule-application</packaging>
8
   <name>yucelmoran-azure-pipeline</name>
9
   <properties>
10
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
12
      <app.runtime>4.3.0</app.runtime>
13
      <mule.maven.plugin.version>3.3.5</mule.maven.plugin.version>
14
      <mule.tools.version>1.7</mule.tools.version>
15
   </properties>
16
   <scm>
17
      <connection>scm:git:git@ssh.dev.azure.com:v3/yucelmorans/yucelmoran-azure-pipeline/yucelmoran-azure-pipeline</connection>
18
      <developerConnection>scm:git@ssh.dev.azure.com:v3/yucelmorans/yucelmoran-azure-pipeline/yucelmoran-azure-pipeline</developerConnection>
19
      <url>https://yucelmorans@dev.azure.com/yucelmorans/yucelmoran-azure-pipeline/_git/yucelmoran-azure-pipeline</url>
20
   </scm>
21
   <distributionManagement>
22
      <repository>
23
         <id>yucelmoran-azure-pipeline</id>
24
         <url>https://pkgs.dev.azure.com/yucelmorans/yucelmoran-azure-pipeline/_packaging/yucelmoran-azure-pipeline/maven/v1</url>
25
      </repository>
26
   </distributionManagement>
27
   <build>
28
      <plugins>
29
         <plugin>
30
            <groupId>org.apache.maven.plugins</groupId>
31
            <artifactId>maven-clean-plugin</artifactId>
32
            <version>3.0.0</version>
33
         </plugin>
34
         <plugin>
35
            <groupId>org.mule.tools.maven</groupId>
36
            <artifactId>mule-maven-plugin</artifactId>
37
            <version>${mule.maven.plugin.version}</version>
38
            <extensions>true</extensions>
39
            <configuration>
40
               <cloudHubDeployment>
41
                  <uri>https://anypoint.mulesoft.com</uri>
42
                  <muleVersion>4.3.0</muleVersion>
43
                  <!-- Deploy User Parameter -->
44
                  <username>${anypoint.username}</username>
45
                  <password>${anypoint.password}</password>
46
                  <!-- Environment Parameter -->
47
                  <environment>Sandbox</environment>
48
                  <applicationName>yucelmoran-azure-pipeline</applicationName>
49
                  <workerType>Micro</workerType>
50
                  <objectStoreV2>true</objectStoreV2>
51
                  <properties>
52
                     <env>${env}</env>
53
                  </properties>
54
               </cloudHubDeployment>
55
            </configuration>
56
            <executions>
57
               <execution>
58
                  <id>deploy</id>
59
                  <phase>deploy</phase>
60
                  <goals>
61
                     <goal>deploy</goal>
62
                  </goals>
63
               </execution>
64
            </executions>
65
         </plugin>
66
         <plugin>
67
            <groupId>org.codehaus.mojo</groupId>
68
            <artifactId>buildnumber-maven-plugin</artifactId>
69
            <version>1.1</version>
70
            <executions>
71
               <execution>
72
                  <id>buildnumber</id>
73
                  <phase>validate</phase>
74
                  <goals>
75
                     <goal>create</goal>
76
                  </goals>
77
               </execution>
78
            </executions>
79
            <configuration>
80
               <format>{0,number}</format>
81
               <items>
82
                  <item>buildNumber</item>
83
               </items>
84
               <doCheck>false</doCheck>
85
               <doUpdate>false</doUpdate>
86
               <revisionOnScmFailure>unknownbuild</revisionOnScmFailure>
87
            </configuration>
88
         </plugin>
89
         <plugin>
90
            <groupId>org.mule.tools.maven</groupId>
91
            <artifactId>mule-app-maven-plugin</artifactId>
92
            <version>${mule.tools.version}</version>
93
            <extensions>true</extensions>
94
         </plugin>
95
         <plugin>
96
            <groupId>org.apache.maven.plugins</groupId>
97
            <artifactId>maven-install-plugin</artifactId>
98
            <version>2.5.2</version>
99
         </plugin>
100
         <plugin>
101
            <groupId>org.apache.maven.plugins</groupId>
102
            <artifactId>maven-deploy-plugin</artifactId>
103
            <version>2.8.2</version>
104
         </plugin>
105
      </plugins>
106
   </build>
107
   <dependencies>
108
      <dependency>
109
         <groupId>org.mule.connectors</groupId>
110
         <artifactId>mule-http-connector</artifactId>
111
         <version>1.5.17</version>
112
         <classifier>mule-plugin</classifier>
113
      </dependency>
114
      <dependency>
115
         <groupId>org.mule.connectors</groupId>
116
         <artifactId>mule-sockets-connector</artifactId>
117
         <version>1.1.6</version>
118
         <classifier>mule-plugin</classifier>
119
      </dependency>
120
      <dependency>
121
         <groupId>org.mule.modules</groupId>
122
         <artifactId>mule-soapkit-module</artifactId>
123
         <version>1.2.6</version>
124
         <classifier>mule-plugin</classifier>
125
      </dependency>
126
      <dependency>
127
         <groupId>org.mule.modules</groupId>
128
         <artifactId>mule-apikit-module</artifactId>
129
         <version>1.3.13</version>
130
         <classifier>mule-plugin</classifier>
131
      </dependency>
132
   </dependencies>
133
   <repositories>
134
      <repository>
135
         <id>yucelmoran-azure-pipeline</id>
136
         <url>https://pkgs.dev.azure.com/yucelmorans/yucelmoran-azure-pipeline/_packaging/yucelmoran-azure-pipeline/maven/v1</url>
137
         <releases>
138
            <enabled>true</enabled>
139
         </releases>
140
         <snapshots>
141
            <enabled>true</enabled>
142
         </snapshots>
143
      </repository>
144
      <repository>
145
         <id>MuleRepository</id>
146
         <name>MuleRepository</name>
147
         <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
148
         <layout>default</layout>
149
         <releases>
150
            <enabled>true</enabled>
151
         </releases>
152
         <snapshots>
153
            <enabled>true</enabled>
154
         </snapshots>
155
      </repository>
156
      <repository>
157
         <id>mulesoft-release</id>
158
         <name>mulesoft release repository</name>
159
         <layout>default</layout>
160
         <url>http://repository.mulesoft.org/releases/</url>
161
         <snapshots>
162
            <enabled>false</enabled>
163
         </snapshots>
164
      </repository>
165
   </repositories>
166
   <pluginRepositories>
167
      <pluginRepository>
168
         <id>mulesoft-release</id>
169
         <name>mulesoft release repository</name>
170
         <layout>default</layout>
171
         <url>http://repository.mulesoft.org/releases/</url>
172
         <snapshots>
173
            <enabled>false</enabled>
174
         </snapshots>
175
      </pluginRepository>
176
      <pluginRepository>
177
         <id>MuleRepository</id>
178
         <name>MuleRepository</name>
179
         <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
180
         <layout>default</layout>
181
      </pluginRepository>
182
   </pluginRepositories>
183
</project>


Basically, we are specifying the location of our repository for source control purposes and then specifying where we want to deploy our application with the cloudHubDeployment configuration in the mule-maven-plugin tag.

We can verify everything works using the following command:

Shell
 




xxxxxxxxxx
1


 
1
mvn clean install -s settings.xml -e


Create a Pipeline

Now we can create our pipeline configuration, find the Pipelines options, and select "Create Pipeline."

image-12.png

Select the Azure Repos Git option and select your repo from your project.

image-13.png

In the next step, we can select Maven and then a template YAML file will be generated (we will change this eventually).

YAML
 




x
22


 
1
# Maven
2
# Build your Java project and run tests with Apache Maven.
3
# Add steps that analyze code, save build artifacts, deploy, and more:
4
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
5

          
6
trigger:
7
- master
8

          
9
pool:
10
  vmImage: 'ubuntu-latest'
11

          
12
steps:
13
- task: Maven@3
14
  inputs:
15
    mavenPomFile: 'pom.xml'
16
    mavenOptions: '-Xmx3072m'
17
    javaHomeOption: 'JDKVersion'
18
    jdkVersionOption: '1.8'
19
    jdkArchitectureOption: 'x64'
20
    publishJUnitResults: true
21
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
22
    goals: 'package'


When you finish the new YAML file will it appear as part of your code. We need to modify the script, in this case, leaving it as shown below:

YAML
 




xxxxxxxxxx
1
36


 
1
# Maven
2
# Aurthor: Edgar Moran
3
# Build your Java project and run tests with Apache Maven.
4
# Add steps that analyze code, save build artifacts, deploy, and more:
5
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
6

          
7
trigger:
8
- test 
9
- emoran
10

          
11
pool:
12
  vmImage: 'ubuntu-latest'
13

          
14
steps:
15
- task: Maven@3
16
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/test'))
17
  inputs:
18
    mavenPomFile: '$(system.defaultWorkingDirectory)/pom.xml'
19
    mavenOptions: '-Xmx3072m'
20
    javaHomeOption: 'JDKVersion'
21
    jdkVersionOption: '1.8'
22
    jdkArchitectureOption: 'x64'
23
    publishJUnitResults: true
24
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
25
    goals: 'clean deploy -Danypoint.username=$(ANYPOINT_USERNAME) -Danypoint.password=$(ANYPOINT_PASSWORD) -Denv=test -Dazure.password=$(AZURE_TOKEN) -Dnexus.username=$(NEXUS_UERNAME) -Dnexus.password=$(NEXUS_PASSWORD) -s settings.xml -e'
26

          
27
- task: Maven@3
28
  inputs:
29
    mavenPomFile: '$(system.defaultWorkingDirectory)/pom.xml'
30
    mavenOptions: '-Xmx3072m'
31
    javaHomeOption: 'JDKVersion'
32
    jdkVersionOption: '1.8'
33
    jdkArchitectureOption: 'x64'
34
    publishJUnitResults: true
35
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
36
    goals: 'clean install -Dazure.password=$(AZURE_TOKEN) -Dnexus.username=$(NEXUS_UERNAME) -Dnexus.password=$(NEXUS_PASSWORD) -s settings.xml -e'


It is important at this step to set the variables we will use during deployment. For example, credentials to login to nexus repositories, Anypoint Platform, and our personal tokens we created in Azure.

Once we have created our pipeline we can select the option Variables:

image-15.png

Finally, let's create as many as we need, according to what we need from our YAML file:

image-16.png

So now the last piece of the puzzle is basically to send a change from the source control to Azure on the first step (sending a change on emoran) branch. For example:

image-17.png
image-18.png

We'll see our pipeline running the emoran branch:

image-19.png

When it finishes, we'll see this brach had a clean install build:

image-20.png

Now everything happens in source control, so if we want to deploy our application to Cloudhub, then we need to promote our changes from the emoran branch to the test branch.

Now, let's create a pull request from Azure, from the emoran branch to the test branch:

Once we click Create, then we need to complete  the pull request and merge request in order to start the pipeline.

When the pipeline that we ran for the test branch finishes, we can see that the deployment happened this time:

So now we can go to Anypoint Platform and see our app deploying:


Finally, you can set as many branches as you need and try out other processes.

I hope this helps! You can find full code here.

I hope to hear from you in the comments!

azure Continuous Integration/Deployment DevOps Git Branch (computer science) source control code style application Pipeline (software)

Opinions expressed by DZone contributors are their own.

Related

  • Deploying MuleSoft Using Azure DevOps
  • Set Up a CI/CD Pipeline for An Angular 7 Application From Azure DevOps to AWS S3 - Part 2
  • Zero to Hero on Kubernetes With Devtron
  • Testing Serverless Functions

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!