# Continuous Integration of Applications to CloudHub 2.0 with Bitbucket

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717564689486/5c5d86e1-5c64-421a-8eea-3adafbe908af.jpeg align="center")

### Prerequisites:

* Bitbucket
    
* Anypoint Platform (Exchange Contributor, Runtime Access)
    

### Mule API Project Structure:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717563266101/777faec7-ba0d-4d26-ae67-46e8a9aa1d1b.png align="center")

### Before you Deploy Mule Application to Cloudhub 2.0

Update Pom xml file with Distribution Management

```xml
<distributionManagement>
  <repository>
    <id>exchange-connected-app-v3</id>
    <name>Exchange Private Repository</name>
    <url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${project.groupId}/maven</url>
    <layout>default</layout>
  </repository>
</distributionManagement>
```

Update Pom Xml with repositories

```xml
<repositories>
		<repository>
			<id>exchange-connected-app-v3</id>
			<name>Anypoint Exchange</name>
			<url>https://maven.anypoint.mulesoft.com/api/v3/maven</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>
```

For groupId please refer [How to know my Organization ID (Org ID) on the Anypoint Platform](https://help.salesforce.com/s/articleView?id=001115130&type=1)

To deploy a Mule application to CloudHub 2.0, the application must first be published to Anypoint Exchange and then deployed.

To publish the application to Anypoint Exchange, create a file named `settings.xml` within it.

```xml
<?xml version="1.0"?>
<settings>

  <pluginGroups>
    <pluginGroup>org.mule.tools</pluginGroup>
  </pluginGroups>

  <servers>
	<server>
		<username>~~~Client~~~</username>
		<password>${CLOUDHUB_CLIENT_ID}~?~${CLOUDHUB_CLIENT_SECRET}</password>
		<id>exchange-connected-app-v3</id>
	  </server>
  </servers>

  <profiles>
	<profile>	
		<properties>
		  <org.id>ffb8acd1-c3ef-428d-8f40-b6e01fa634c2</org.id>
		</properties>
		<repositories>
		  <repository>
			<id>exchange-connected-app-v3</id>
			<name>Corporate Repository</name>
			<url>https://maven.anypoint.mulesoft.com/api/v3/organizations/${org.id}/maven</url>
		  </repository>
		  <repository>
			<id>exchange-connected-app-v2</id>
			<name>Corporate Repository</name>
			<url>https://maven.anypoint.mulesoft.com/api/v2/organizations/${org.id}/maven</url>
		  </repository>
		</repositories>
		<id>exchange-repos</id>
	  </profile>
  </profiles>

	<activeProfiles>
    <activeProfile>exchange-repos</activeProfile>
  </activeProfiles>
  
</settings>
```

This repository will serve as an example. The code for your Mule application should be stored here.

After your code is uploaded to Bitbucket, create a new YAML file containing the pipeline's actual code.

```yaml
image: maven:3.8.4-openjdk-8

pipelines:
    branches:
      develop:
        - step:
            name: Git Security Scan
            caches:
                - maven
            script:
                - pipe: atlassian/git-secrets-scan:0.5.1  
        - step:
            name: Validate & Compile
            caches:
                - maven 
            script:          
                - mvn -B clean -DskipTests package
          step:
            name: Publish to Exchange
            caches:
                - maven 
            script:
                - mvn deploy -s settings.xml
        - step:
            name: Deploy to dev cloudhub
            deployment: Sandbox
            caches:
                - maven
            script:  
                - mvn deploy -s settings.xml -DmuleDeploy -Denvironment=Sandbox -DtargetName=Cloudhub-US-East-2 -DmuleVersion=4.6.2 -Dworkers=1 -DworkerType=MICRO -DCLOUDHUB_CLIENT_ID=$CLOUDHUB_CLIENT_ID -DCLOUDHUB_CLIENT_SECRET=$CLOUDHUB_CLIENT_SECRET -DappName=mule-cloudhub2-deploy14
```

### Create Deployment enveironment:

create a environment in bitbucket Named as per the deployment environment added in the **Deploy to dev cloudhub** step.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717564310749/d2e87c63-a2cc-4360-bdc5-9a3b3ca3c4e6.png align="center")

### Update Repository Variables:

For connected app credentials refer [Connected App functionality](https://help.salesforce.com/s/articleView?id=001115971&type=1)

update connected app secrets in repository settings as below

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717563506732/6a0dbf2a-ab70-45ea-b9a8-0a8e4a7edc68.png align="center")

In the above bibucket yaml is written to run manually, In Pipelines select branch and step to run the pipeline as below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717563675900/4dd39293-73f3-41eb-87f1-29c68583113f.png align="center")

once the pipeline is triggered application will be published to Anypoint Exchange and deployed.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717563911240/036905eb-e7e2-4e9c-b4cf-4ac238ee61cd.png align="center")

Application deployed to Cloudhub 2.0.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1717565114178/327f85c3-e56c-4de4-be0d-86b2905c7549.png align="center")
