Implementing Bamboo CICD For CH 2.0 Using Connected App

Author: Atharva Gondhalekar

1) Introduction

CI in CI/CD means Continuous Integration and CD refers to Continuous Deployment or Delivery which is a systematic approach used to automate application delivery in different stages of application development. It is an easier method to quickly identify problems while introducing a new functionality. It allows us to check if code is breaking and perform unit tests at various stages as designed.

While deploying Apps as a part of the new CH 2.0 lifecycle you need to :

  1. Deploy your app to Exchange.
  2. Deploy it to your CloudHub Shared or Private Space.
2) Steps to Deploy to Cloudhub 2.0

Let’s now proceed with the step-by-step procedure.

2.1. Creating Connected App on MuleSoft Platform

Navigate to the Access Management tab and click on Connected Apps.

1. Click Create App.

2. Give a unique name to your App and select App acts on its own behalf (client credentials).

3. Add the following Scopes to your App.

  • Exchange Contributor
    • Exchange Administrator
  • Design Centre
    • Design Centre Developer
  • To deploy applications in Runtime Manager,you need:
    • Create Applications
    • Read Applications
  • General
    • View Environment
    • View Organization

4. Review the configurations and save your app.

5. Make sure to note down the username and password for this connected app.

2.2. Configure Settings.xml
  • In your settings file, make sure you have the following servers.
<server>
		<id>YOUR_SERVER_ID</id>
		<!-- NOTE: In order to publish assets to exchange, the user will need Exchange Contributor Role -->
		<username>~~~Client~~~</username>
        <password>${connectedApp.user}~?~${connectedApp.password}</password>
	</server>
	<server>
		<id>mulesoft-enterprise-edition</id>
		<username>${mule.nexus.username}</username>
		<password>${mule.nexus.password}</password>
	</server>
	<!-- Customer Exchange Repository -->
	<server>
		<id>anypoint-exchange-v3</id>
		<username>~~~Client~~~</username>
        <password>${connectedApp.user}~?~${connectedApp.password}</password>
	</server>
	<server>
		<id>YOUR_PRIVATE_EXCHANGE_ID</id>
        <username>~~~Client~~~</username>
        <password>${connectedApp.user}~?~${connectedApp.password}</password>
	</server>

Also, check if the following repositories are present.

<profile>
	<id>Mule</id>
	<activation>
		<activeByDefault>true</activeByDefault>
	</activation>
	<repositories>
		<repository>
			<id>PRIVATE_EXCHANGE_ID_DEFINIED_IN_SETTINGS</id>
			<name>SOME_NAME</name>
			<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/YOUR_ORG_ID/maven/</url>
			<layout>default</layout>
		</repository>
		<repository>
			<id>mulesoft-enterprise-edition</id>
			<name>Mulesoft EE</name>
			<url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
			<layout>default</layout>
		</repository>
		<repository>
			<id>mulesoft-releases</id>
			<name>MuleSoft Releases Repository</name>
			<url>https://repository.mulesoft.org/releases/</url>
			<layout>default</layout>
		</repository>
		<repository>
			<id>anypoint-exchange-v3</id>
			<name>Anypoint Exchange V3</name>
			<url>https://maven.anypoint.mulesoft.com/api/v3/maven</url>
			<layout>default</layout>
		</repository>
	</repositories>
	<pluginRepositories/>
	</profile>
  </profiles>
2.3. Configure pom.xml
  • Change the group id with your Orgs Group ID
<groupId>YOUR_ORG_GROUP_ID</groupId>

You can find the Org Id as shown in the figure below when you log in to the Anypoint platform:

Figure 1: Organisation Id
  • Make sure packaging is mule-application
  • Update Mule Maven plugin version to 3.8.1.
  • Add a distribution management  tag pointing to PRIVATE_EXCHANGE_ID_DEFINIED_IN_SETTINGS just below properties and before Build tag
<distributionManagement>
		<repository>
			<id>PRIVATE_EXCHANGE_ID_DEFINIED_IN_SETTINGS</id>
			<name>Anypoint Exchange</name>
			<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
			<layout>default</layout>
		</repository>
	</distributionManagement>
  • Add a Maven plugin as follows. Make sure the version is 0.0.15.
<plugin>
				<groupId>org.mule.tools.maven</groupId>
				<artifactId>mule-maven-plugin</artifactId>
<artifactId>exchange-mule-maven-plugin</artifactId>
				<version>0.0.15</version>
				<executions>
					<execution>
						<id>validate</id>
						<phase>validate</phase>
						<goals>
							<goal>exchange-pre-deploy</goal>
						</goals>
					</execution>
					<execution>
						<id>deploy</id>
						<phase>deploy</phase>
						<goals>
							<goal>exchange-deploy</goal>
						</goals>
					</execution>
				</executions>
				<version>${mule.maven.plugin.version}</version>
				<extensions>true</extensions>
				<configuration>
					<classifier>mule-application</classifier>
					<cloudhub2Deployment>
						<uri>https://anypoint.mulesoft.com</uri>
						<provider>MC</provider>
						<environment>${cloudhub.env}</environment>
						<businessGroupId>YOUR_ORG_GROUP_ID</businessGroupId>
						<target>${target}</target>
						<muleVersion>${app.runtime}</muleVersion>
						<server>YOUR_SERVER_ID_DEFINED_IN_SETTINGS</server>
						<applicationName>${app.name}</applicationName>
						<replicas>${app.replicas}</replicas>
						<vCores>${app.vcores}</vCores>
						<properties>
							<mule.env>${mule.env}</mule.env>
							<anypoint.platform.client_id>${anypoint_platform_client_id}</anypoint.platform.client_id>
						</properties>
						<secureProperties>
							<encryption.key>${encryption.key}</encryption.key>
							<anypoint.platform.client_secret>${anypoint_platform_client_secret}</anypoint.platform.client_secret>
						</secureProperties>
						<deploymentSettings>
							<lastMileSecurity>false</lastMileSecurity>
							<forwardSslSession>false</forwardSslSession>
							<generateDefaultPublicUrl>true</generateDefaultPublicUrl>
						</deploymentSettings>
					</cloudhub2Deployment>
				</configuration>
			</plugin>

Environment: This is the CloudHub V2 environment name. Make sure it matches your environment name.

target: This is the CloudHub V2 Shared Space Region Name or the Private Space name (available on Runtime Manager -> Private Spaces) where you want to deploy the App.

You can add your own properties and secure properties as required.

We have 12 regions available for deployment to a shared space. They are:

  1. Cloudhub-US-East-1
  2. Cloudhub-US-East-2
  3. Cloudhub-US-West-1
  4. Cloudhub-US-West-2
  5. Cloudhub-EU-West-1
  6. Cloudhub-EU-West-2
  7. Cloudhub-AP-Southeast-1
  8. Cloudhub-AP-Southeast-2
  9. Cloudhub-AP-Northeast-1
  10. Cloudhub-SA-East-1
  11. Cloudhub-EU-Central-1
  12. Cloudhub-CA-Central-1
  • Make sure to include Anypoint Exchange V3, V2, your Private Exchange, and MuleSoft Releases repositories in the repository section.
  • Add the MuleSoft Releases plugin repository at the end.
2.4. Configuring Bamboo Pipeline
  • Go to your Bamboo Pipeline, navigate inside your Project, and click on ‘Create Plan’.
Figure 2: Create a bamboo plan
  • Select your project and fill in all the details.
Figure 3: Create Plan
  • Proceed and Link a repository for a given Branch.
  • Once your plan is created, click on configure plan.
Figure 4: Configure Plan
  • Go to variables and configure the variables you will need for this plan.
Figure 5: Variables
  • Go to the Stages tab and click on the default job.
  • Here, you can configure various tasks that are needed for your plan.
2.5. Configuring tasks in Bamboo

We will look at some sample tasks that can be configured in a Bamboo plan.

  1. Source Code Checkout – Give a description and select our repository.
  2. As discussed above, we have to first deploy the app to Anypoint Exchange. We can configure a Maven 3.X task for that and define a goal of clean deploy, passing our required arguments using -D.

Eg. clean deploy -s maven/settings.xml -DskipMunitTests -DconnectedApp.user=${bamboo.connectedApp_user_dev} -DconnectedApp.password=${bamboo.connectedApp_password_dev} -Dencryption.key=${bamboo.encryption_secret} -Dmule.env=${bamboo.env}

Note:

1. We can access bamboo variables using bamboo <our variable name>.

2. We have to provide the path of the settings file using the -s command. In the example above, the settings file is inside the Maven folder at the root directory of the project.

Figure 6: Bamboo Tasks

After this step, you can check if your app is deployed or not in the exchange at the following URL.

https://anypoint.mulesoft.com/exchange/?type=app&show=all)

  1. After deploying to the exchange, we then have to deploy the app to the platform’s runtime manager. For that, we can use the following command.

clean deploy –DmuleDeploy -s maven/settings.xml -DskipMunitTests -DconnectedApp.user=${bamboo.connectedApp_user_dev} -DconnectedApp.password=${bamboo.connectedApp_password_dev} -Dencryption.key=${bamboo.encryption_secret} -Dmule.env=${bamboo.env}

Make sure to pass all the arguments required by the app, as described in the pom.xml above, e.g., target, environment, mule.env, encryption.key, etc. Otherwise, Bamboo will not be able to find the runtime properties, and the deployment will fail.

App will be deployed to CloudHub.

  1. Now, normally after a run, a version should be updated in the pom.xml for the next run. For that, we can add the following plugins and profiles in the pom.xml.
PLUGINS to be Added in pom.xml
<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<version>3.2.0</version>
				<executions>
					<execution>
						<id>parse-version</id>
						<goals>
							<goal>parse-version</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>versions-maven-plugin</artifactId>
				<version>2.8.1</version>
			</plugin>
Profiles to be Added in pom.xml
<profiles>
		<profile>
			<id>bump-patch</id>
			<activation>
				<property>
					<name>bumpPatch</name>
				</property>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>versions-maven-plugin</artifactId>

						<executions>
							<execution>
								<goals>
									<goal>set</goal>
								</goals>
								<phase>validate</phase>
								<configuration>
									<newVersion>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</newVersion>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>bump-minor</id>
			<activation>
				<property>
					<name>bumpMinor</name>
				</property>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>versions-maven-plugin</artifactId>

						<executions>
							<execution>
								<goals>
									<goal>set</goal>
								</goals>
								<phase>validate</phase>
								<configuration>
									<newVersion>${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0</newVersion>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>bump-major</id>
			<activation>
				<property>
					<name>bumpMajor</name>
				</property>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.codehaus.mojo</groupId>
						<artifactId>versions-maven-plugin</artifactId>

						<executions>
							<execution>
								<goals>
									<goal>set</goal>
								</goals>
								<phase>validate</phase>
								<configuration>
									<newVersion>${parsedVersion.nextMajorVersion}.0.0</newVersion>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

We can then create a Maven 3.X task and use the following command as the goal.

validate -DbumpPatch -s maven/settings.xml -DskipMunitTests

For example, if the version in the pom (according to semantic versioning) is 1.0.0, using ‘bumpPatch’ will make it 1.0.1.

Similarly, bumpMinor will make it 1.1.0 and bumpMajor will make it 2.0.0

  1. Finally, the version change should be committed back to the source repository for the next tasks to proceed. To achieve this, we use the ‘Repository Commit’ task in Bamboo, select our repository, and provide a generic commit message, e.g., ‘version incremented’.
2.6 Changes to be made if deploying to CH 1.0

Configure all steps up to 2.3 in the same way. In step 2.3, do not configure the Distribution Management tag.

Add the following Mule Maven plugin :

<plugi<plugin>
  <groupId>org.mule.tools.maven</groupId>
  <artifactId>mule-maven-plugin</artifactId>
  <version>3.7.1</version>
  <extensions>true</extensions>
  <configuration>
    <cloudHubDeployment>
      <uri>https://anypoint.mulesoft.com</uri>
      <muleVersion>${app.runtime}</muleVersion>
      <username>${username}</username>
      <password>${password}</password>
      <applicationName>${cloudhub.application.name}</applicationName>
      <environment>${environment}</environment>
      <region>${region}</region>
      <workers>${workers}</workers>
      <workerType>${workerType}</workerType>
      <properties>
        <key>value</key>
      </properties>
    </cloudHubDeployment>
  </configuration>
</plugin>

Keep the rest of the things the same and proceed with the following steps.

mvn clean deploy -DmuleDeploy
3. References
  1. https://docs.mulesoft.com/cloudhub-2/ch2-deploy-maven
  2. #01: Anypoint CloudHub2.0 | Deploying Mulesoft Application using Mule Maven Plugin
  3. https://apisero.com/implementing-ci-cd-in-mule-using-jenkins
  4. https://blogs.infomentum.com/deploy-to-cloudhub-maven-and-app
  5. https://www.atlassian.com/
  6. https://medium.com/javarevisited/how-to-increment-versions-for-the-maven-build-java-project-a7596cc501c2
  7. https://docs.mulesoft.com/mule-runtime/4.4/deploy-to-cloudhub
  8. https://dzone.com/articles/mule-maven-plugin-for-deploying-mulesoft-applicati
4. Links to be Whitelisted on Bamboo
  1. maven.anypoint.mulesoft.com
  2. repository.mulesoft.org
  3. repo.maven.apache.org
  4. repository-master.mulesoft.org
  5. jitpack.io
  6. java.net
  7. mule-manager.anypoint.mulesoft.com
  8. mule-manager.eu1.anypoint.mulesoft.com
  9. runtime-manager.anypoint.mulesoft.com
  10. runtime-manager.eu1.anypoint.mulesoft.com
  11. runtime-manager.gov.anypoint.mulesoft.com
  12. arm-auth-proxy.prod.cloudhub.io
  13. data-authenticator.anypoint.mulesoft.com
  14. data-authenticator.gov.anypoint.mulesoft.com
  15. mule-manager.anypoint.mulesoft.com
  16. mule-manager.eu1.anypoint.mulesoft.com
  17. runtime-manager.anypoint.mulesoft.com
  18. runtime-manager.eu1.anypoint.mulesoft.com
  19. runtime-manager.gov.anypoint.mulesoft.com

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.