Mulesoft 4: Continuous Delivery/Deployment With Maven
The main aim of this article is to provide a standard mechanism to release project artifacts and deploy to Anypoint Platform.
Join the DZone community and get the full member experience.
Join For FreeThe main aim of this article is to provide a standard mechanism to release project artifacts and deploy to Anypoint Platform, from the local machine or configure in continuous delivery pipelines.
Normally multiple people involved in the deployment process, one team/team member may handle check-in of code, others may handle configuration, and so on. very likely that any step may be missed out due to manual efforts.
For example:
- Untested code gets to build and deploy.
- Uncommitted code gets to build and deploy.
- The deployment team deployed the older build again.
- Running local build fails on the server.
- Configuration, not sync’s.
Prerequisites
Minimum Anypoint Platform Role
CloudHub Developer / Developer
Exchange Contributors
Anypoint Platform Credentials
To deploy mule applications using a mule maven plugin, need to set the Anypoint platform credentials, please update Anypoint platform credentials information in the .m2/settings.xml as the following:
<servers>
<server>
<id>MuleExchangeRepository</id>
<username>anypoint_platfrom_id</username>
<password>anypoint_platfrom_password</password>
</server>
</servers>
Update GroupId in POM.XML
To set of identifiers to update groupId with an Organization ID.
xxxxxxxxxx
<groupId>[Organization ID]</groupId>
Update SCM (Source Code/Control Management) Details in POM.XML
To release prepare mule applications using a mule maven plugin, we need to update SCM details.
xxxxxxxxxx
<scm>
<connection>scm:git:https://github.com/repo/${project.artifactId}.git</connection>
<url>https://github.com/repo/${project.artifactId}</url>
<developerConnection>scm:git:https://github.com/repo/${project.artifactId}.git</developerConnection>
<tag>HEAD</tag>
</scm>
Update Distribution Management
To release perform and upload deployable mule applications using a mule maven plugin, need to update Distribution Management details.
xxxxxxxxxx
<distributionManagement>
<repository>
<id>MuleExchangeRepository</id>
<name>Mule Exchange Repository</name>
<url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${project.groupId}/maven</url>
<layout>default</layout>
</repository>
</distributionManagement>
For CloudHub Deployment
Update pom.xml with cloudHub Deployment configuration.
xxxxxxxxxx
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
<cloudHubDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>${muleVersion}</muleVersion>
<applicationName>${project.artifactId}</applicationName>
<environment>${cloud.env}</environment>
<businessGroup>${anypoint.businessGroup}</businessGroup>
<region>${region}</region>
<workers>${workers}</workers>
<workerType>${workerType}</workerType>
<server>${server}</server>
<properties>
<env>${app.env}</env>
</properties>
</cloudHubDeployment>
</configuration>
</plugin>
</plugins>
</build>
For Runtime Fabric Deployment
Update pom.xml with Runtime Fabric Deployment configuration.
x
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
<runtimeFabricDeployment>
<uri>https://anypoint.mulesoft.com</uri>
<muleVersion>4.2.2</muleVersion>
<provider>MC</provider>
<businessGroup>${anypoint.businessGroup}</businessGroup>
<environment>${cloud.env}</environment>
<target>${target}</target>
<applicationName>${project.artifactId}</applicationName>
<server>${server}</server>
<deploymentSettings>
<replicationFactor>${replicationFactor}</replicationFactor>
<cpuReserved>${cpuReserved}</cpuReserved>
<cpuMax>${cpuMax}</cpuMax>
<memoryReserved>${memoryReserved}</memoryReserved>
<publicUrl>${project.artifactId}.${loadbalancer}</publicUrl>
</deploymentSettings>
<properties>
<env>${app.env}</env>
</properties>
</runtimeFabricDeployment>
</configuration>
</plugin>
</plugins>
</build>
For Standalone Runtime Deployment
Update pom.xml with Standalone Runtime Deployment configuration.
xxxxxxxxxx
<build>
<plugins>
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<standaloneDeployment>
<muleHome>${mule.home}</muleHome>
</standaloneDeployment>
</configuration>
</plugin>
</plugins>
</build>
Release
Release:Prepare
After configuring all the prerequisites, make sure you are pointing at the branch you want to release. all your code is committed and pushed and pulled the latest version from origin
run: mvn release:prepare
The release:prepare goal will:
- Verify that there are no uncommitted changes in the workspace.
- Verify that there are no SNAPSHOT dependencies
- Prompt the user for the desired tag, release, and development version names.
- Modify and commit release information into the pom.xml file.
- Tag the entire project source tree with the new tag name.
- Move forward the version in the POMs to next SNAPSHOT version
- Commit the modified POMs.
Release:Perform
Checks out the code using the previously defined tag and run the Maven deploy goal, upload deployable or artifact to Anypoint Exchange repository.
mvn -B release:perform
Deployment
Please check out the release tag for deployment:
git checkout --no-track -b deploytag <deployment-tag> --
To CloudHub
mvn deploy -DmuleDeploy -DmuleVersion=?
-Dcloud.env=?
-Danypoint.businessGroup=?
-Dregion=?
-Dworkers=?
-DworkerType=?
-Dserver=?
-Dapp.env=?
To Runtime Fabric
mvn deploy -DmuleDeploy -Danypoint.businessGroup=?
-Dcloud.env=?
-Dtarget=?
-Dproject.artifactId=?
-Dserver=?
-DreplicationFactor=?
-DcpuReserved=?
-DcpuMax=?
-DmemoryReserved=?
-Dproject.artifactId=?
-Dloadbalance=?
-Dapp.env=?
To Standalone
mvn deploy -DmuleDeploy -Dmule.home=?
Please refer to Mulesoft Documentation for Additional information.
Thanks!
Opinions expressed by DZone contributors are their own.
Comments