Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (118 sloc) 6.87 KB
type layout title excerpt published last_modified_at header toc_icon categories tags meta
post
single
PowerShell Core on Travis CI (part 1 of 3)
How to build, test, and deploy your PowerShell projects on Linux and macOS for free with Travis CI! {::nomarkdown}<br><br>Example available in the <strong>Armor PowerShell</strong> project.<br><br><iframe style="display: inline-block;" src="https://ghbtns.com/github-btn.html?user=tlindsay42&repo=armorpowershell&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe> <iframe style="display: inline-block;" src="https://ghbtns.com/github-btn.html?user=tlindsay42&repo=armorpowershell&type=fork&count=true&size=large" frameborder="0" scrolling="0" width="158px" height="30px"></iframe>{:/nomarkdown}
true
2018-05-20
overlay_image overlay_filter teaser
/assets/images/powershell_github_travis-ci.png
0.5
/assets/images/powershell_github_travis-ci.png
terminal
Automation
Continuous Delivery
Continuous Deployment
Continuous Integration
FOSS
Free
GitHub
Linux
macOS
Microsoft
Open source
OSX
PowerShell
PowerShell Core
Travis CI
Ubuntu
_wpcom_is_markdown _thumbnail_id _rest_api_published _rest_api_client_id _publicize_job_id _publicize_done_external _publicize_done_18611616 _wpas_done_18402702 publicize_twitter_user publicize_google_plus_url _publicize_done_18611618 _wpas_done_18402704 publicize_linkedin_url _publicize_done_18611619 _wpas_done_18402705
1
307
1
-1
11837283676
a:1:{s:7:"twitter";a:1:{i:18402702;s:59:"https://twitter.com/troylindsay42/status/934648058633076736";}}
1
1
troylindsay42
1
1
1
1

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][enable]
  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][gem] includes both a [command line client][cli] and a [Ruby library][lib] 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][lint] your .travis.yml file.

Install Ruby

Windows

On Windows, we [recommend][windows] using the [RubyInstaller][installer], 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][homebrew] to install a recent version:

brew install ruby
gem update --system

Install the Travis ruby gem

Make sure you have at least [Ruby][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][part_2].

[enable]: {{ '/assets/images/enable.png' | relative_url }} 'enable button' [lint]: https://en.wikipedia.org/wiki/Lint_(software) "validating" [gem]: https://rubygems.org/gems/travis [cli]: https://github.com/travis-ci/travis.rb#command-line-client [lib]: https://github.com/travis-ci/travis.rb#ruby-library [windows]: https://github.com/travis-ci/travis.rb#windows [installer]: http://rubyinstaller.org/ [homebrew]: http://mxcl.github.io/homebrew/ [ruby]: http://www.ruby-lang.org/en/downloads/ [part_2]: {% post_url 2017-11-25-powershell-core-on-travis-ci-part-2 %}