travis_ciIn order to deal with the amount of different projects Knowm Inc. is currently managing, both open source and commercial, we jumped at the opportunity to move all of our OSS projects over from an in-house Jenkins CI to a free hosted Travis CI service. Doing so frees us up from having to maintain our Jenkins server, deal with it hanging, updating it, etc. This is just one more step in streamlining project development and management. The only disadvantage by doing this was the loss of our Sonar code quality analytics, but I suspect something of the sort will soon become available as a plugin to Travis CI.

What we needed Travis CI to do though was a bit non-standard, and we wanted to write what we learned here for future reference, but also to help other get their Maven builds deploying snapshots to a repository. This article assumes you’ve already setup your Travis CI account and have followed the standard setup procedures and configurations linking your Travis CI and GitHub accounts and projects. Make sure to enable the Travis CI hook in GitHub too. The example configurations contain stuff relevant to our project XChart, and you’ll have to adapt your configurations to your specific project’s properties.

References

Our initial inquiry on Travis Google group
Our second inquiry on Travis Google group
Travis gem and secure variables
Knowm’s XChart project on GitHub
XChart’s Travis CI page

settings.xml

Simply add another branch to your project called travis, remove everything from it, and place the following settings.xml file in it.

Setup Travis Command Line Tool

You’ll need to run some commands on a machine where ruby is installed and the travis gem is installed.

Generate Encrypted Variables

The artifact repo requires a username and password of course, and we don’t want to have those as plain-text in the above settings.xml file. Therefore we use the following commands to generate the encrypted keys. Obviously replace timmolter/XChart with your own Github account name and project name. The username and password correspond to the login info you created during Sonatype’s Nexus repository system.

.travis.yml

Place a file called .travis.yml in the root of the project on the branch you want to be deployed. You’ll need to modify this .travis.yml file as shown here. The whitelist specifies that we only want the build to run on the develop branch. Replace the keys below with your generated codes from the previous step. Note that the script line prevents snapshots being deployed when an update on the develop branch is due to a pull request. To prevent a snapshot deploy on a pull request the script checks the Travis environment variable TRAVIS_PULL_REQUEST and if it is a pull request, it runs mvn clean verify. Otherwise, it runs mvn clean deploy as we want.

Test It

Now that everything is setup, all you need to do is push a change on the develop branch to GitHub, and Travis CI will build the Maven project and deploy the artifacts to a snapshot repo automatically!

Other Travis CI Tidbits

  1. Pushes that have [ci skip] anywhere in one of the commit messages will be ignored.
  2. EDIT – this issue has now been fixed. You may need to place a .travis.yml file in all your project’s branches to prevent it to try to build those branches – even if your whitelist doesn’t include those branches. They are planning on changing this behavior though.
  3. Embed a Travis CI build badge in REAME.md file:

Related Posts

Subscribe To Our Newsletter

Join our low volume mailing list to receive the latest news and updates from our team.

Leave a Comment

Knowm 32X32 Crossbar

Knowm Newsletter

Are you ready for memristor AI processors? With our newsletter, you will be.