Mule Application Deployment using TeamCity

Mazhar Ansari
5 min readSep 28, 2020

Note: While copy/paste the code snippet from blog please covert quotes and double quotes.

In this blog we will try to learn how we can TeamCity as CI/CD pipeline tool for Mule application deployment. Please refer to my last blog to use docker images of TeamCity.

What is TeamCity?

  • TeamCity is a build management and continuous integration server from JetBrains.
Ci/CD Pipeline

Features of TeamCity

  • It provides several ways to reuse the settings of the parent project to sub-project.
  • For a single build Teamcity can take source code from two different VCS.
  • It can also detect builds which are hung.
  • For easy access you can mark build.
  • We can run parallel builds simultaneously in different environments.
  • Formatted text can be set for Build status which makes the server perform some actions.
  • You can build docker images in separate steps with the extension to other runners (Gradle, Maven, etc).
  • Testers can be replaced with agents.

Mule Project Overview:

  • Here How Mule flow look like
Mule Flow
  • Here is xml File
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="dd6bdb1d-aab0–4ca0–81d1–9ce208e7d371" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="deployment-demoFlow" doc:id="7e6054f0-c25d-461c-9db0-ba13f9e85fb9" >
<http:listener doc:name="Listener" doc:id="1710f78c-c002–4a78–8aec-0823cc307cd7" path="/deployment" config-ref="HTTP_Listener_config"/>
<ee:transform doc:name="Transform Message" doc:id="ff3c9737–4d43–4055–821a-de0095d0ceb0" >
<ee:message >
<ee:set-payload >
<![CDATA[%dw 2.0
output text/plain
- -
"Application Deployed Using CI/CD Pipeline"]]>
</ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>

Mule Project POM Setting for CloudHub Deployment:

  • Add below fragments in pom.xml under project -> build -> plugins
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<cloudHubDeployment>
<objectStoreV2>true</objectStoreV2>
<uri>https://anypoint.mulesoft.com/</uri>
<muleVersion>4.2.2</muleVersion>
<username>Change Me</username>
<password>Change Me</password>
<applicationName>deployment-demo-poc</applicationName>
<environment>Sandbox</environment>
<workerType>Micro</workerType>
<workers>1</workers>
<region>us-west-2</region>
</cloudHubDeployment>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
POM.xml Configuration

Accepted values for region:

  • us-east-1 — US East (N. Virginia)
  • us-west-2 — US West (Oregon)
  • eu-west-1 — EU (Ireland)
  • ap-southeast-2 — Asia Pacific (Sydney)
  • ap-southeast-1 — Asia Pacific (Singapore)
  • us-west-1 — US West (N. California)
  • eu-central-1 — EU (Frankfurt)
  • ap-northeast-1 — Asia Pacific (Tokyo)
  • eu-west-2 — EU (London)
  • ca-central-1 — Canada (Central)
  • sa-east-1 — South America (São Paulo)
  • us-east-2 — US East (Ohio)

Accepted values for workerType:

  • MICRO(0.1 vCores)
  • SMALL (0.2 vCores),
  • MEDIUM (1 vCores)
  • LARGE (2 vCores)
  • XLARGE (4 vCores)
  • XXLARGE (8 vCores)
  • 4XLARGE (16 vCores)

Mule Project POM Setting for On-Premises Mule Instances using Runtime Manager REST API deployment:

  • Add below fragments in pom.xml under project -> build -> plugins
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<armDeployment>
<muleVersion>${app.runtime}</muleVersion>
<uri>https://anypoint.mulesoft.com</uri>
<target>Change Me</target>
<targetType>server</targetType>
<username>Change Me</username>
<password>Change Me</password>
<environment>Sandbox}</environment>
<properties>
<key>value</key>
</properties>
</armDeployment>
</configuration>
<executions>
<execution>
<id>deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
POM.xml Configuration
  • Commit the code in the SCM repository in my case its bitbucket.

Configure TeamCity:

TeamCity Login Page
  • Provide required information and click on “Log In
  • Click On “Create Project
TeamCity Projects Page
  • Provide the source code management details in my case I am using bitbucket
TeamCity Create Project
  • Click on “Proceed
TeamCity SCM Details Page
  • Click on “Proceed
TeamCity Auto Detect Build Steps
  • Click on “configure build steps manually
TeamCity Manually Add Build Steps
  • Click on “Add build step
TeamCity Build Step Runner Type
  • Choose “Command Line” or “Maven
TeamCity Build Step Details
  • Fill the Information as shown below for Command Line
Step name: Clean and Install
Custom script: /opt/buildagent/tools/maven3_6/bin/mvn clean install
  • Fill the Information as shown below for Maven
Step name: Clean and Install
Custom script: mvn clean install
  • Click on “Save
TeamCity Build Steps Details
  • Follow the steps for add build step and create one more step with below configuration (Command Line).
Step name: Package and Deploy
Run: Custom script
Custom script: /opt/buildagent/tools/maven3_6/bin/mvn package deploy -DmuleDeploy
  • Follow the steps for add build step and create one more step with below configuration (Maven).
Step name: Clean and Install
Custom script: mvn package deploy -DmuleDeploy
TeamCity Build Steps Details

Note: As of now second step is not parameterized however you can make it parameterized as well.

  • We are done with setup and can run the build by clicking on “Run” or else push some changes to github.
TeamCity Build Details
  • It will take some time to complete. We can see the progress by clicking on “Build Log
TeamCity Build Logs
TeamCity Build Logs
  • Click on “Overview
TeamCity Build Details
  • To see all previous builds click on “Build”. As of now I have only one build executed.
TeamCity Build History
  • If you want to change the build and update it. Click on “Edit Configuration Setting
TeamCity Build Options
  • You can change Version Control Setting, Steps, Triggers etc.

--

--

Mazhar Ansari

I am seasoned Integration Architect with around 18+ yrs of exp. I have extensively worked on TIBCO and Mulesoft. Mainly in EAI, ESB, SOA, API and BPM projects.