Triggering a Travis Build Programmatically
For Exalibur.js we wanted to be able to keep our
master branch documentation up-to-date on the website. The website is built using Assemble.io and GitHub pages and after successfully automating my blog, naturally I turned to Travis CI to set up automated documentation generation.
Travis normally sets up a hook in your GitHub repository to automatically trigger a build after you push a commit (or pull request). This is real nice but unfortunately that's where it stops. If you want to trigger a build for another repository, you have to do it manually.
I asked Travis about this and their response is promising (Twitter can be nice sometimes):
@kamranayub it's on the roadmap, and hopefully landing soon <3March 29, 2015
Until that time, though, something has to be done.
One approach I saw was a small Ruby script to forge a webhook POST message. This is actually a nice idea but since Excalibur uses Node to build, I needed something else and didn't want to port it over.
Instead I borrowed some code from @patrickketner that uses the node-travis-ci npm package to submit a build through the public API. I modified Patrick's code since I need to use GitHub personal access tokens like I did previously.
You still need to follow the same steps to set up the
GH_TOKEN environment variable but once you do, all you have to do is execute this Node.js script (changing the
So for example, in your
.travis.yml file, you just need:
install: - npm install travis-ci after_success: - node trigger-build.js
All set. Now when you commit to one repository, you can trigger a build for another one. This allows us to automatically keep our docs up-to-date with whatever
You can reference Excalibur to see how we execute the script. Additionally, you can reference excaliburjs.com's Travis configuration to see how we use TypeDoc to generate documentation for the latest version of