Using continuous deployment with CloudHub

July 11 2013

3 comments 0
motif

Introduction

After creating a basic Mule App, you might be wondering how to automate the process of deploying a Mule App to CloudHub. In this post, we are introducing a Maven plugin that enables that use case. As a result a Mule App will be deployed automatically to CloudHub after a Maven build. This is achieved using the goal cloudhub-deploy from the Mule AppKit Maven Plugin.

In a ideal development workflow, each time the project builds the Mule Application will be deployed to the cloud providing a cutting edge instance that can be used for QA of the latest snapshot. Both Bamboo or Jenkins can be configured in order to run Maven and deploy the Mule App to CloudHub.

Show me the code

Given an existing Mule App (created using the Mule Application Archetype), we have a Maven pom.xml file. Check that the project has as packaging type mule. Then, add the following to the build > plugins pom.xml section:

<plugin>
    <groupId>org.mule.tools.appkit</groupId>
    <artifactId>mule-appkit-maven-plugin</artifactId>
    <version>3.4</version>
    <extensions>true</extensions>
    <executions>
        <execution>
            <!-- This can be changed to any Maven phase -->
            <phase>deploy</phase>
            <goals>
                <goal>cloudhub-deploy</goal>
            </goals>
            <configuration>
                <!-- Where the app will be deployed -->
                <domain>${cloudhub.domain}</domain>
                <!-- Max wait time in millisecs before timeout -->
                <maxWaitTime>180000</maxWaitTime>
            </configuration>
        </execution>
    </executions>
</plugin>

The property cloudhub.domain must be set in the properties block. This is where the app is going to be deployed:

<properties>
    <!-- This is the domain where the app will be 
        deployed: i.e. mydomain.cloudhub.io -->
    <cloudhub.domain>mydomain</cloudhub.domain>
</properties>

And in the settings.xml file a server must be added together with some valid credentials for CloudHub so that the deploy can take place. This will be the credentials used for the deploy:

Include the plugin repository (where the AppKit Maven Plugin is hosted) in the pom.xml file:

<pluginRepositories>
  <pluginRepository>
    <id>mulesoft-releases</id>
    <name>MuleSoft Release Repository</name>
    <url>http://repository.mulesoft.org/releases/</url>
  </pluginRepository>
  <pluginRepository>
    <id>mulesoft-snapshots</id>
    <name>MuleSoft Snapshot Repository</name>
    <url>http://repository.mulesoft.org/snapshots/</url>
  </pluginRepository>
</pluginRepositories>

After that, run the deploy maven goal:

$ mvn clean deploy

and the app will be deployed to CloudHub.

Wait! I don’t want to deploy my artifacts yet!

As deploy Maven Phase is related also with Artifact Deployment, it can be better to change the plugin deployment phase to verify. On that way, and by doing mvn clean verify, it can achieve the same result without having to upload the resulting Maven artifact to a remote repository.

That’s great but where can I find some usage examples?

Some working examples can be found in Mule Appkit integration tests: here and here.

Happy Hacking!


We'd love to hear your opinion on this post

3 Responses to “Using continuous deployment with CloudHub”

  1. Hi Alberto,
    I have two questions:
    – can I use this plugin also for deploying(uplaoding) my Mule app to the MMC repository?
    – when I try using the plugin in my project I get the error:
    ——————-
    Failed to parse plugin descriptor for org.mule.tools.appkit:mule-appkit-maven-plugin:3.4 (C:\Users\pascal\.m2\repository\org\mule\tools\appkit\mule-appkit-maven-plugin\3.4\mule-appkit-maven-plugin-3.4.jar): JAR entry META-INF/maven/lifecycle.xml not found in C:\Users\pascal\.m2\repository\org\mule\tools\appkit\mule-appkit-maven-plugin\3.4\mule-appkit-maven-plugin-3.4.jar
    ——————–
    Any ideas how to fix this?

    Regards,
    Pascal

    Agree(0)Disagree(0)Comment
  2. Heads up to everyone that have multiple CloudHub environments. In order to deploy you must specify the environment you are deploying to or you’ll get the following error: “You do not have access to perform that action”.

    In order to specify which environment you are deploying to, use [email protected] in the XML tag.

    Example:

    cloudhub.io
    [email protected]
    password

    Agree(0)Disagree(0)Comment
  3. This blog is similar to the purpose of the mule-maven-plugin https://docs.mulesoft.com/mule-user-guide/v/3.8/mule-maven-plugin, I wonder which is the recommended approach? Is the apikit no longer maintained, as it has not been updated since 2013?

    Agree(0)Disagree(0)Comment