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

Configuring Travis CI to Deploy MuleSoft Application To CloudHub

DZone 's Guide to

Configuring Travis CI to Deploy MuleSoft Application To CloudHub

In this article, we discuss how to configure Travis CI to deploy a MuleSoft application to CloudHub.

· DevOps Zone ·
Free Resource

Introduction

Travis CI is a continuous integration and deployment tool and it can easily build the server, which is hosted on GitHub, where projects can easily build, tested and deployed.

Travis CI is capable of building pull requests. Travis CI is available at https://travis-ci.org/. For open-source projects or public repositories on Github, Travis CI is free.

travis-ci.org supports only public repositories. To support Github private repositories, you can use https://travis-ci.com/.

Prerequisites

You need to make sure that you have a GitHub account, and this GitHub account can be used to login into travis-ci.

Setting Up Travis CI

For setting up, you can navigate to https://travis-ci.org/ and use GitHub account to login to Travis CI. Now, it will navigate you to Authorize Travis-CI screen and click on Authorize travis-ci.

Once travis-ci has been authorized, it will navigate to Travis CI homepage. Now, you can go to GitHub ⇒ Settings ⇒ Application. You will see authorized applications under Authorized OAuth Apps.

Adding Repository to Travis CI

For adding repositories to travis ci, you need to go to the home page of travis ci and click on (+) near My Repositories.

Once you click on the (+) button, you will see all public repositories in your GitHub.

Public repositories

Any repository shown in the above list can be activated by clicking the Switch button. Once you activate the repository in travis-ci, it will create webhooks in GitHub. Navigate to your repository ⇒ Settings ⇒ Webhooks

GitHub Webhooks

One important thing to notice — you need to create a .travis.yml file at the root of your project for build to run.

.travis.yml Configuration

Travis requires a .travis.yml configuration file to initiate the build or run. Minimum requirement in .travis.yml is language.

YAML


For our build, we will be using Maven, so the language will be Java. A list of languages supported by Travis can be found here: https://docs.travis-ci.com/user/languages/.. travis-ci.yml can be validated here: https://config.travis-ci.com/explore.

Example .travis.yml for Maven will look like this.

YAML


For deploying MuleSoft application to cloudhub, you need to configure mule maven plugin in POM.xml

XML


Create the file, .travis.settings.xml, at the root of your project. It will contain a username and password for your AnyPoint platform.

Server attributes in the mule maven plugin will be id in .travis.settings.xml.

XML


${env.username} and ${env.password} will be read from Travis CI environment variables. This username and password will be your AnyPoint Platform username and password.

Declaring Environment Variables at Travis CI

For declaring the variable, you can activate the repository and click on settings. It will navigate to the build screen. Now click on More Options ⇒ Settings. It will navigate to the screen where you can declare environment variables.

In above screen, all environment variables have been declared — required by Mule maven plugin like workers, workerType, Application Name, etc. and username and password required by .travis.settings.xml

Below is the complete .travis.yml, which will perform the automatic deployment to MuleSoft CloudHub, whenever code is pushed to dev branch or any pull request created to the dev branch.

YAML


For accessing environment variables, syntax is $variableName. Travis-CI provided the option to perform trigger manual build. It also provided an option to see running build logs, build history, branches.

Configuring Travis CI for Deploying MuleSoft Application - Part I | Github | Travis CI | MuleSoft


Configuring Travis CI for Deploying MuleSoft Application - Part II | Postman | Newman | MuleSoft

These above 2 videos will give complete information on how you can use Travis CI to perform automated deployments and testing using Newman and Postman for MuleSoft Applications.

Topics:
ci/cd, cloudhub, devops, mulesoft, travis ci, tutorial

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}