Manually trigger Travis CI builds on Pull Requests

This tutorial deals with pull requests on Github which have Travis CI integration.

The day before this was written, Travis CI experienced some issues as a result of which some builds didn’t complete. I had a pull-request open at the time, and the build for it was stuck at “waiting for build status”.

Usually, at that point you would perform a manual build. But if you don’t have access to the repository or the Travis instance, here’s how you can trigger a manual build.

    1. Open a terminal, go to your project directory and checkout the branch from which you created the pull request.
      $ git checkout <some-cool-new-feature-branch>
    2. Amend the last commit with:
      $ git commit --amend

      When git opens your commit message, save and quit.

    3. Force-push to your feature branch.
      $ git push -f <your-fork> <some-cool-new-feature-branch>
    4. Voila! You should see a new build has been triggered.

This works because when you amend your last commit, the commit-hash changes, which leads your CI to see it as a fresh commit for which it hasn’t run the build yet. Since commit-hashes take into account the timestamp of the commit, you will always get a different hash when you perfom a git commit --amend.

A word of caution, though. This rewrites your git history, so you have to be careful when you are doing this. Ideally, don’t do this on branches that others depend on / are based off of.

Originally seen on this comment.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s