Author: Mohammad Mazhar Ansari
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.

Features of TeamCity
- It provides several ways to reuse the settings of the parent project to subproject.
- 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 is how Mule flow looks like

- 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>

Accepted values for Regions:
- 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>

- Commit the code in the SCM repository. In my case, its bitbucket.
Configure TeamCity:
- Open to TeamCity Server URL in browser.
- http://192.168.56.101:9111/login.html

- Provide required information and click on “Log In”.
- Click On “Create Project”.

- Provide the source code management details. In my case, I am using bitbucket.

- Click on “Proceed”.

- Click on “Proceed”.

- Click on “configure build steps manually”.

- Click on “Add build step”.

- Choose “Command Line”.

- Fill the Information as shown below.
Step name: Clean and Install
Custom script: /opt/buildagent/tools/maven3_6/bin/mvn clean install
- Click on “Save”.

- Follow the steps for add build step and create one more step with below configuration.
Step name: Package and Deploy
Run: Custom script
Custom script: /opt/buildagent/tools/maven3_6/bin/mvn package deploy -DmuleDeploy

- We are done with setup and can run the build by clicking on “Run” or else push some changes to github.

- It will take some time to complete. We can see the progress by clicking on “Build Log”.


- Click on “Overview”.

- To see all previous builds click on “Build”. As of now, I have only one build executed.

- If you want to change the build and update it, then click on “Edit Configuration Setting”.

- You can change Version Control Setting, Steps, Triggers, etc.