{{announcement.body}}
{{announcement.title}}

Mulesoft 4: Continuous Delivery/Deployment With Maven

DZone 's Guide to

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.

· Integration Zone ·
Free Resource

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

XML
 




x
13
9


1
<servers>
2
        <server>
3
              <id>MuleExchangeRepository</id>
4
              <username>anypoint_platfrom_id</username>
5
              <password>anypoint_platfrom_password</password>
6
        </server>
7
</servers>



Update GroupId in POM.XML

To set of identifiers to update groupId with an Organization ID. 

XML
 




xxxxxxxxxx
1


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

XML
 




xxxxxxxxxx
1


 
1
<scm>
2
    <connection>scm:git:https://github.com/repo/${project.artifactId}.git</connection>
3
    <url>https://github.com/repo/${project.artifactId}</url>
4
    <developerConnection>scm:git:https://github.com/repo/${project.artifactId}.git</developerConnection>
5
    <tag>HEAD</tag>
6
</scm>



Update Distribution Management

To release perform and upload deployable mule applications using a mule maven plugin, need to update Distribution Management details.

XML
 




xxxxxxxxxx
1


 
1
<distributionManagement>
2
    <repository>
3
        <id>MuleExchangeRepository</id>
4
        <name>Mule Exchange Repository</name>
5
        <url>https://maven.anypoint.mulesoft.com/api/v1/organizations/${project.groupId}/maven</url>
6
        <layout>default</layout>
7
    </repository>
8
</distributionManagement>
9
 
          



For CloudHub Deployment

Update pom.xml with cloudHub Deployment configuration.

XML
 




xxxxxxxxxx
1
28


 
1
<build>
2
    <plugins>
3
        <plugin>
4
            <groupId>org.mule.tools.maven</groupId>
5
            <artifactId>mule-maven-plugin</artifactId>
6
            <version>${mule.maven.plugin.version}</version>
7
            <extensions>true</extensions>
8
            <configuration>
9
                <classifier>mule-application</classifier>                
10
                <cloudHubDeployment>
11
                    <uri>https://anypoint.mulesoft.com</uri>
12
                    <muleVersion>${muleVersion}</muleVersion>
13
                    <applicationName>${project.artifactId}</applicationName>
14
                    <environment>${cloud.env}</environment>
15
                    <businessGroup>${anypoint.businessGroup}</businessGroup>
16
                    <region>${region}</region>
17
                    <workers>${workers}</workers>
18
                    <workerType>${workerType}</workerType>
19
                    <server>${server}</server>
20
                    <properties>
21
                        <env>${app.env}</env>
22
                    </properties>
23
                </cloudHubDeployment>
24
            </configuration>
25
        </plugin>
26
    </plugins>
27
</build>



For Runtime Fabric Deployment

Update pom.xml with Runtime Fabric Deployment configuration.

XML
 




x
1
34


 
1
<build>
2
    <plugins>
3
        <plugin>
4
            <groupId>org.mule.tools.maven</groupId>
5
            <artifactId>mule-maven-plugin</artifactId>
6
            <version>${mule.maven.plugin.version}</version>
7
            <extensions>true</extensions>
8
            <configuration>
9
            <classifier>mule-application</classifier>                
10
                <runtimeFabricDeployment>
11
                    <uri>https://anypoint.mulesoft.com</uri>
12
                    <muleVersion>4.2.2</muleVersion>
13
                    <provider>MC</provider>
14
                    <businessGroup>${anypoint.businessGroup}</businessGroup>
15
                    <environment>${cloud.env}</environment>
16
                    <target>${target}</target>
17
                    <applicationName>${project.artifactId}</applicationName>
18
                    <server>${server}</server>
19
                    <deploymentSettings>
20
                        <replicationFactor>${replicationFactor}</replicationFactor>
21
                        <cpuReserved>${cpuReserved}</cpuReserved>
22
                        <cpuMax>${cpuMax}</cpuMax>
23
                        <memoryReserved>${memoryReserved}</memoryReserved>
24
                        <publicUrl>${project.artifactId}.${loadbalancer}</publicUrl>
25
                    </deploymentSettings>
26
                    <properties>
27
                        <env>${app.env}</env>
28
                    </properties>
29
                </runtimeFabricDeployment>  
30
            </configuration>
31
        </plugin>
32
    </plugins>
33
</build>
34



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

Please refer to Mulesoft Documentation for Additional information.

Thanks!

Topics:
deployment, integration, maven-release-plugin, mule 4, mulesoft 4

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}