Over a million developers have joined DZone.

Automated Deployment with Mule Management Console and Maven

Automated deployment doesn't have to be difficult. Learn how to use the Mule management console and Maven to achieve automated deployment.

· DevOps Zone

The DevOps Zone is brought to you in partnership with Sonatype Nexus. The Nexus Suite helps scale your DevOps delivery with continuous component intelligence integrated into development tools, including Eclipse, IntelliJ, Jenkins, Bamboo, SonarQube and more. Schedule a demo today

In my opinion a deployment of any application should be as automated as possible to avoid errors due to manual mistakes. This is no different with a Mule ESB application. If you are using the Enterprise Edition of the Mule ESB you also have the ability to make use of the Mule Management Console (MMC). This instrument makes the governance of the deployment of your Mule applications into different environments easier and therefore the whole deployment cycle less error-prone.


One item that I am missing in the MMC is to automatically add a new version of your Mule Application into the MMC. You can upload your Mule applications manually with MuleStudio (which enforces you to use MuleStudio of which I am not a big fan) or by uploading it by using the MMC itself being also manually.


Luckily there is one escape for this which is the REST API that is available for the MMC. Combined with a Maven plugin you can have your Mule application uploaded to the MMC and deployed automatically. Although Mulesoft doesn’t supply this plugin themselves I found an open source version here. I used this as my starting point and added a few enhancements that are useful (at least in my situation). The sources can be found here.
The situation I added is the following:


In case I upload a ‘SNAPSHOT’ version of an application, the existing application is removed from the MMC repository and the new SNAPSHOT version is added. In case of a non-snapshot version only a new version is allowed, an error message is received otherwise. Deployments that are already using the SNAPSHOT version will be redeployed with the new version. As a rule a SNAPSHOT version should only be deployed to the Test environment and never make it to Acceptance or Production.


When you have added the plugin to your Maven repository you can use it in your Mule project by adding the following configuration to your pom:

...
<build>
  <plugins>
    <plugin>
      <groupId>org.mule.tools</groupId>
      <artifactId>mule-mmc-rest-plugin</artifactId>
      <version>1.1.1-SNAPSHOT</version>
      <executions>
        <execution>
          <id>mule-deploy</id>
          <phase>install</phase>
          <goals>
            <goal>deploy</goal>
          </goals>
          <configuration>
            <muleApiUrl>${muleApiUrl}</muleApiUrl>
            <name>${artifactId}</name>
            <username>admin</username>
            <password>admin</password>
            <appDirectory>${project.basedir}/src/main/app</appDirectory>
            <finalName>${artifactId}-${version}</finalName>
            <version>${version}</version>
            <serverGroup>Test</serverGroup>
          </configuration>
        </execution>
      </executions>
    </plugin>
    ...
  </plugins>
</build>
...

In my parent pom I have defined the property ‘muleApiUrl’ as:

...
<properties>
  <muleApiUrl>http://mmc-host:8080/mmc/api</muleApiUrl>
<properties>
...

The ServerGroup ‘Test’ refers to my Test Server in the MMC:
mmc-screenshot
So every time I run ‘mvn install’ the Mule application is added to the repository of MMC and deployed to the Test environment. From the MMC it can then be promoted to Acceptance or Production.

The DevOps Zone is brought to you in partnership with Sonatype Nexus. Use the Nexus Suite to automate your software supply chain and ensure you're using the highest quality open source components at every step of the development lifecycle. Get Nexus today

Topics:
web dev ,maven ,automated deployment

Published at DZone with permission of Pascal Alma, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}