{{announcement.body}}
{{announcement.title}}

Deploying MuleSoft Using Azure DevOps

DZone 's Guide to

Deploying MuleSoft Using Azure DevOps

This article introduces Azure DevOps and provides a step-by-step guide on how to deploy MuleSoft with Azure DevOps.

· DevOps Zone ·
Free Resource

Azure DevOps Server is a Microsoft product that provides version control, reporting, requirements management, project management, automated builds, lab management, testing and release management capabilities. In short, it covers the entire application lifecycle and enables DevOps capabilities. 

Here we are going to see how to implement CI/CD pipeline for MuleSoft application using Azure DevOps.

Azure CI/CD

Azure CI/CD


Step 1: Make sure you have added the Mule-Maven plugin in your pom.xml

XML
 




x
39


 
1
<plugin>
2
  <groupId>org.mule.tools.maven</groupId>
3
  <artifactId>mule-maven-plugin</artifactId>
4
  <version>3.3.1</version>
5
  <extensions>true</extensions>
6
    <configuration>
7
        <cloudHubDeployment>
8
            <uri>https://anypoint.mulesoft.com</uri>
9
            <muleVersion>${app.runtime}</muleVersion>
10
            <username>${anypoint.username}</username>
11
            <password>${anypoint.password}</password>
12
            <businessGroup>${businessGroup}</businessGroup>
13
            <workers>${workers}</workers>
14
            <workerType>${workerType}</workerType>
15
            <region>us-west-1</region>
16
            <environment>${environment}</environment>
17
            <applicationName>${applicationName}</applicationName>
18
            <properties>
19
                <mule.env>${mule.env}</mule.env>
20
                <encrypt.key>${encrypt.key}</encrypt.key>                   <anypoint.platform.client_id>${anypoint.platform.client_id}     </anypoint.platform.client_id>      <anypoint.platform.client_secret>${anypoint.platform.client_secret}</anypoint.platform.client_secret>
21
                <api.id>${ilg.api.version}</api.id>
22
    <anypoint.platform.config.analytics.agent.enabled>true</anypoint.platform.config.analytics.agent.enabled>
23
            </properties>
24
        </cloudHubDeployment>
25
                    <executions>
26
                        <execution>
27
                            <id>deploy</id>
28
                            <goals>
29
                                <goal>deploy</goal>
30
                            </goals>
31
                            <configuration>
32
                                <classifier>mule-application</classifier>
33
                            </configuration>
34
                        </execution>
35
                    </executions>
36
                    
37
                            <classifier>mule-application</classifier>
38
                </configuration>
39
            </plugin>



The <cloudHubDeployment> tag of the Mule Maven plugin defines the attributes of your deployable.

So let's see what each of these properties tells us about the deployment onto CloudHub. 

  • uri: Mulesoft Anypoint platform URL
  • muleVersion: Mulesoft version to be used for deployment(e.g. 4.2.3).
  • username: Username for Anypoint platform.
  • password: Password for Anypoint platform.
  • businessGroup: Business group of the Anypoint platform under which you want to deploy your application.
  • workers: The number of workers to be assigned to the application. This is used for horizontal scaling.
  • workerType: The number of vCores to be assigned to the application. This is used for vertical scaling.
  • region: Region to be used while deploying the application.
  • environment: Environment onto which application needs to be deployed.
  • applicationName: Application name to be deployed. 
  • properties: Provide here all the properties which are required by application at deployment time i.e. encryption key.

Step 2: Login into your Azure DevOps account. There are two ways to create a pipeline.

First, you can go to the Pipelines tab and click a new pipeline.

Creating a new pipeline

Creating a new pipeline


Or you can go to your repositories where you have your files and you can select the Build Pipeline option.

Build pipeline from repositories

Build pipeline from repositories


Let’s create it using the Create pipeline option. 

Go to Pipeline and Create Pipeline.

Creating pipeline

Creating pipeline


Select Classic Editor as it gives better customization.

Using classic editor

Using classic editor


Source

You can select your source where your code is stored. In my case, it’s in Azure Repos.

Further, select your Team Project, Repository and branch.

Then, click continue.

Continue

Continue


Template

Select the Maven template.

Maven template

Maven template


This is the default screen you’ll see.

Default screen

Default screen


I’ll be removing all the three steps created under the Agent job and customize it according to my requirements.

Customization

Customization


Firstly, I am adding “Download secure file.” I’ll be using it to download settings.xml.

Download secure file

Download secure file


But to download and use secure file in our pipeline we need to store our file somewhere.

In order to add settings.xml go to Pipelines → Library → Secure files and add (+) Secure files.

On clicking + navigate to settings.xml:

Settings.xml

Settings.xml


Make sure your settings.xml has below server and profile added under the respective tags.

XML
 




xxxxxxxxxx
1
27


 
1
<server>
2
    <id>Exchange2</id>
3
    <username>guest-mule</username>
4
    <password>Mulesoft1</password>
5
</server>
6
 
          
7
<profile>
8
 
          
9
        <id>Mule</id>
10
        <activation>
11
            <activeByDefault>true</activeByDefault>
12
        </activation>
13
        <repositories>
14
            <repository>
15
                <id>Exchange2</id>
16
                <name>Exchange2</name>
17
                <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
18
                <layout>default</layout>
19
                <releases>
20
                    <enabled>true</enabled>
21
                </releases>
22
                           <snapshots>
23
                    <enabled>true</enabled>
24
               </snapshots>
25
            </repository>
26
        </repositories>
27
 </profile>


Now the settings which we created needs to be selected as below in our step.

Selecting settings

Selecting settings


Now let’s create a reference name “mulesoftSettingsFile” for this settings file which we are going to use later in maven goals. 

Creating reference name

Creating reference name


Let’s add the next step in the Agent job, which will be Maven. 

Adding Maven

Adding Maven


In Options, we have given the secure settings file a reference name which we created in the previous step.

Providing reference name

Providing reference name


We require "username" and "password" for the Anypoint platform to be provided at build time, so lets create two variables for them and pass it into the Maven setup for deployment. 

Add variable

Add variable


Now let’s add the final Step which will be performed by our Agent

Package deploy

Package deploy


Now let's run the pipeline. We can either save the pipeline using "Save" or save it and run using the "Save and run" option.

Saving the pipeline

Saving the pipeline


Once the pipeline gets completed executed you will see below screen.

Finalize job

Finalize job



And you will be able to see the application deployed onto CloudHub. We can add more steps into the CI/CD pipeline, like code analysis, testing, and report generation.

We have successfully created a CI/CD pipeline using Azure DevOps and deployed an application to CloudHub.

Topics:
azure ,azure devops ,cicd pipeline ,cloudhub ,devops ,mule ,mulesoft ,mulesoft 4

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}