Trigger a Travis-CI rebuild without pushing a commit?

Travis Ci

Travis Ci Problem Overview


Using Travis-CI, is it possible to trigger a rebuild without pushing a new commit to GitHub?

Use case: A build fails due to an externality. The source is actually correct. It would build OK and pass if simply re-run.

For instance, an apt-get fails due to a package server being down, but the server is back up again. However the build status is "stuck" at "failed" until a new commit is pushed.

Is there some way to nudge Travis-CI to do another build, other than pushing a "dummy" commit?

Travis Ci Solutions


Solution 1 - Travis Ci

  • If you have write access to the repo: On the build's detail screen, there is a button ↻ Restart Build. Also under "More Options" there is a trigger build menu item.

    Note: Browser extensions like Ghostery may prevent the restart button from being displayed. Try disabling the extension or white-listing Travis CI.

    Note2: If .travis.yml configuration has changed in the upstream, clicking rebuild button will run travis with old configuration. To apply upstream changes for travis configuration one has to add commit to PR or to close / reopen it.

  • If you've sent a pull request: You can close the PR then open it again. This will trigger a new build.

Restart Build:

Restart Build Screen Shot

Trigger Build:

Trigger Build Screen Shot

Solution 2 - Travis Ci

If you open the Settings tab for the repository on GitHub, click on Integrations & services, find Travis CI and click Edit, you should see a Test Service button. This will trigger a build.

Solution 3 - Travis Ci

I know you said without pushing a commit, but something that is handy, if you are working on a branch other than master, is to commit an empty commit.

git commit --allow-empty -m "Trigger"

You can rebase in the end and remove squash/remove the empty commits and works across all git hooks :)

Solution 4 - Travis Ci

I have found another way of forcing re-run CI builds and other triggers:

  1. Run git commit --amend --no-edit without any changes. This will recreate the last commit in the current branch.
  2. git push --force-with-lease origin pr-branch.

Solution 5 - Travis Ci

If you have new project on GitHub which has .travis.yml, but was never tested, you can run tests without commit this way:

  1. enable testing in Travis CI setings
  2. open project page on GitHub
  3. open settings -> webhooks and services
  4. find Travis CI in services and press edit button
  5. press "Test service"

Solution 6 - Travis Ci

You can do this using the Travis CLI. As described in the documentation, first install the CLI tool, then:

travis login --org --auto
travis token

You can keep this token in an environment variable TRAVIS_TOKEN, as long as the file you keep it in is not version-controlled somewhere public.

I use this function to submit triggers:

function travis_trigger() {
     local org=$1 && shift
     local repo=$1 && shift
     local branch=${1:-master} && shift

     body="{
             \"request\": {
               \"branch\": \"${branch}\"
              }
           }"

     curl -s -X POST \
          -H "Content-Type: application/json" \
          -H "Accept: application/json" \
          -H "Travis-API-Version: 3" \
          -H "Authorization: token $TRAVIS_TOKEN" \
          -d "$body" \
          "https://api.travis-ci.org/repo/${org}%2F${repo}/requests"
 }

Solution 7 - Travis Ci

Travis now offers a way to trigger a "custom" build from their web UI. Look for the "More Options" menu button on the right side near the top of your project's page.

More Options → Trigger Build

You'll then be presented with a dialog box in which you can choose the branch and customize the configuration:

Custom Build Dialog Box

At the time I'm writing this it is in beta, and appears to be slightly buggy (but I expect they'll get the problems ironed out soon).

Solution 8 - Travis Ci

If you install the Travis CI Client you can use travis restart <job#> to manually re-run a build from the console. You can find the last job# for a branch using travis show <branch>

travis show master
travis restart 48 #use Job number without .1
travis logs master

Travis CI Client

UPDATE: Sadly it looks like this doesn't start a new build using the latest commit, but instead just restarts a previous build using the previous state of the repo.

Solution 9 - Travis Ci

If the build never occurred (perhaps you didn't get the Pull-Request build switch set to on in time), you can mark the Pull Request on Github as closed then mark it as opened and a new build will be triggered.

Solution 10 - Travis Ci

I should mention here that we now have a means of triggering a new build on the web. See https://blog.travis-ci.com/2017-08-24-trigger-custom-build for details.

TL;DR Click on "More options", and choose "Trigger build".

Solution 11 - Travis Ci

I just triggered the tests on a pull request to be re-run by clicking 'update branch' here: github check tests component

Solution 12 - Travis Ci

Here's what worked for me to trigger a rebuild on a PR that Dependabot had opened, but failed due to errors in .travis.yml:

  1. Close the PR
  2. Wait for Dependabot to comment ("OK, I won't notify you again about this release, but will get in touch when a new version is available."). It will remove its branch.
  3. Restore the branch Dependabot removed (something like dependabot/cargo/tempfile-3.0.4).
  4. Open the PR again

Solution 13 - Travis Ci

Please make sure to Log In to Travis first. The rebuild button doesn't appear until you're logged in. I know this is obvious, but someone just tripped on it as well ;-)

Solution 14 - Travis Ci

sometimes it happens that server do made some mistakes. try log out/sign in and everything might be right then. (Yes it happened this afternoon to me.)

Solution 15 - Travis Ci

Simlpy close and re-open the PR if you do not have the write access.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGreg HendershottView Question on Stackoverflow
Solution 1 - Travis CijbtuleView Answer on Stackoverflow
Solution 2 - Travis CiAaron HillView Answer on Stackoverflow
Solution 3 - Travis CijasonmitView Answer on Stackoverflow
Solution 4 - Travis CiVlad FrolovView Answer on Stackoverflow
Solution 5 - Travis CilampslaveView Answer on Stackoverflow
Solution 6 - Travis CiSam BrightmanView Answer on Stackoverflow
Solution 7 - Travis CiiconoclastView Answer on Stackoverflow
Solution 8 - Travis CiGreg BrayView Answer on Stackoverflow
Solution 9 - Travis CiviperguynazView Answer on Stackoverflow
Solution 10 - Travis CibanzaimanView Answer on Stackoverflow
Solution 11 - Travis CiFrazer KirkmanView Answer on Stackoverflow
Solution 12 - Travis CigrooveplexView Answer on Stackoverflow
Solution 13 - Travis CidinvladView Answer on Stackoverflow
Solution 14 - Travis CiXenoAmessView Answer on Stackoverflow
Solution 15 - Travis CiPunit NaikView Answer on Stackoverflow