Overview

Last month, I started a new pet project of building an open-source PowerShell module for Armor, and one of the first goals that came to mind was that I wanted to ensure compatibility with PowerShell Core on Linux.  I had recently re-read Chris Wahl’s article: How to Version and Publish a PowerShell Module to GitHub and PSGallery with AppVeyor, and figured that there had to be a similar service for Linux, so I started looking around.  I found Travis CI rather quickly, and was pleasantly surprised to discover that they offered macOS images in addition to Ubuntu.

If you are unfamiliar with Travis CI, here is a solid description:

Travis CI is a hosted, distributed continuous integration service used to build and test projects hosted at GitHub. Travis CI automatically detects when a commit has been made and pushed to a GitHub repository that is using Travis CI, and each time this happens, it will try to build the project and run tests. This includes commits to all branches, not just to the master branch.

Restated, this means that every time you push new code up to your public repo, Travis CI (and/or AppVeyor) will build your project per your specifications, run any tests defined, and even deploy it if desired.  For free.  Build, test, and deploy on push for free.  How cool is that?

Now, one of the reasons that I am writing this article is that getting started with building & testing a PowerShell project on Travis CI was not intuitive.  AppVeyor and Travis CI were both designed for building, testing, and deploying programming language projects, not [scripting language] projects.  It took a lot of RTFM and a little trial & error to figure it out, but it was so worth it.  The following article covers some of my lessons learned in the process.  I hope that you find them valuable.

Getting started with Travis CI

  1. Sign into Travis CI with your GitHub account and accept the GitHub access permissions confirmation.
  2. Once you’re signed in to Travis CI, and we’ve synchronized your GitHub repositories, go to your profile page and enable the repository you want to build: enable button
  3. Add a .travis.yml file to your repository to tell Travis CI what to do.
  4. Add the .travis.yml file to git, commit and push, to trigger a Travis CI build:
    1. Travis only runs builds on the commits you push after you’ve enabled the repository in Travis CI.
  5. Check the build status page to see if your build passes or fails, according to the return status of the build command

Not too bad, right?  Don’t worry, there isn’t that much more even though the scroll bar indicates otherwise.

Install the Travis Client

The travis gem includes both a command line client and a Ruby library to interface with a Travis CI service.

You’ll need the Travis Client on your workstation for encrypting sensitive data such as access tokens as well as for linting your .travis.yml file.

Install Ruby

Windows

On Windows, we recommend using the RubyInstaller, which includes the latest version of Ruby

Mac OS X via Homebrew

Mac OSX prior to 10.9 ships with a very dated Ruby version. You can use Homebrew to install a recent version:

brew install ruby
gem update --system

Install the Travis ruby gem

Make sure you have at least Ruby 1.9.3 (2.0.0 recommended) installed. You can check your Ruby version by running ruby -v:

ruby -v
ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]

Then run:

gem install travis -v 1.8.8 --no-rdoc --no-ri

Now make sure everything is working:

travis version
1.8.8

Continued in Part 2.

Improve this page

Comments