434

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?

Greg Hendershott
  • 16,100
  • 6
  • 36
  • 53

15 Answers15

477
  • 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

jbtule
  • 31,383
  • 12
  • 95
  • 128
  • 2
    I have found and used that in other cases. But I could have sworn I had a case where it had Errored for the reason I described above, and the gear menu lacked that option. Perhaps that was a one-time fluke, or perhaps I was mistaken. Anyway, I think you answered how it's _supposed_ to work, so I'll go ahead and mark your answer as accepted. Thanks! – Greg Hendershott Jul 12 '13 at 23:38
  • I can't find that option as well. Is there another way? – guy mograbi Jul 18 '13 at 07:25
  • 3
    If I look at the build history of any of the projects I own, errored or failed, it has a [restart button](https://dl.dropboxusercontent.com/u/14785065/Img/travis-ci.jpg) – jbtule Jul 18 '13 at 12:44
  • 21
    I think one tricky case is where you submit a pull request for someone else's project, and it errored for reasons unrelated to your PR per se, and you _know_ it would succeed if you could just nudge it to try again. It's understandable why you can't (not your project) -- but also understandable why you'd want to (your PR incorrectly "looks bad"). – Greg Hendershott Oct 20 '13 at 10:36
  • 96
    Don't forget you have to be signed in to see this :P – Michael J. Calkins Jan 08 '14 at 22:24
  • 8
    And you need to have write access to the github repro. So this won't work for forks pushed upstream. – Izhaki Jul 09 '14 at 12:01
  • 1
    Plus you actually have to _have_ a build to press the restart button on. – David Given Jun 19 '15 at 20:12
  • 1
    What can you do if the build was never triggered in the first place *and* there isn't a Pull Request open? (ie. it's just a commit on a branch, maybe even on `master`) – wisew Aug 04 '15 at 01:24
  • What do you do if the button is there, you click it, and it says the job was successfully restarted, but there is no other indication that it did? – Sammy Larbi Mar 01 '16 at 18:25
  • 1
    NOTE: This will NOT reconfigure the build, so if there has been a fix on upstream to the build process itself (such as chaning `before_install` in `.travis.yml`), this will NOT be applied by clicking that button: https://github.com/travis-ci/travis-ci/issues/6031#issuecomment-218139497 – Gerry May 10 '16 at 14:12
  • @Gerry Has point there, pushing rebuild button doesn't account changes in `.travis.yml` etc. In that case one has to add new commit or close / reopen the pull request. – Mikael Lepistö Feb 16 '17 at 22:56
  • The downside of this approach is that it replaces the existing build with the new build. If what you want is to trigger a new build (perhaps to demonstrate something that's changed environmentally between that build and now), the Restart Build button is not what you want. – Jason R. Coombs May 31 '17 at 14:12
  • `git ci --amend --no-edit && git push origin [your-branch] --force` will trigger a Travis CI rebuild. But be caution since this will override the previous commit. – Lizhen Hu Jun 13 '19 at 01:24
  • I don't find this button. Has it been removed? – Uri Jan 24 '20 at 07:10
  • @uri it needs a new screen shot but it’s still there when you are logged in under the “more options” drop down – jbtule Jan 29 '20 at 13:25
  • @jbtule It's not there at all. – Uri Jan 29 '20 at 17:27
  • Updated screen shots. – jbtule Jan 29 '20 at 17:42
  • @uri “my repositories” is blank so I think that is where your problem is, it doesn’t see you as having any ownership on the repo. – jbtule Feb 14 '20 at 19:50
  • 1
    @jbtule there was a problem with cookies with Travis CI - after I logged out and logged in again, this button exists. I think they have a separate cookie for repositories, separate from the login cookies. – Uri Apr 01 '20 at 10:54
209

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.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
Aaron Hill
  • 3,196
  • 1
  • 18
  • 34
  • 6
    I think travis-ci removed the restart build button, so this is the only way that worked for me right. It performs *two* builds though… – Blaise Jun 06 '14 at 22:21
  • 1
    @Blaise by any chance do you use Ghostery (or similar)? Try disabling that. For me, this cause the Restart Build button to reappear. – Greg Hendershott Jun 17 '14 at 20:21
  • 29
    This works when you initially activate the Travis CI building for a repo. The "reload build" button doesn't exist for a repo that doesn't have any previous builds. – Brian J. Miller Feb 05 '15 at 21:27
  • 12
    A note for idiots like me: Open `Settings` in the repository _on Github_, not on Travis's repo page! I can't believe I wasted 20 mins trying to find `Service Hooks` on Travis's page. :( – John Red Mar 12 '16 at 11:36
  • Cannot see this option in github. – elena Jun 30 '21 at 20:51
90

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 :)

jasonmit
  • 1,268
  • 8
  • 8
  • 1
    That is brilliant, thank you! I just want to add that I had to rebase in order to move the "Trigger" commit further down in history; otherwise it would simply discard the new build upon removal of the "Trigger" commit. – smheidrich Oct 15 '15 at 16:10
  • 71
    in the same vein, you can amend the existing commit and force push: git commit --amend --no-edit && git push -f – grahamrhay Dec 09 '15 at 16:36
  • 4
    @grahamrhay that's the best to trigger a PR build when you're not the owner of the target repo, it keeps the contents, no need to merge or rebase or do anything. Please make it an answer so it's possible to upvote it more visibly. – TWiStErRob Jan 11 '16 at 18:22
  • I forked a repository I didn't have access to, and this was the only thing that worked for me because Travis didn't have any builds I could restart on my newly created fork. – Nick McCurdy Apr 29 '16 at 06:50
  • 1
    @TWiStErRob Someone else wrote such an answer below. – Franklin Yu Jan 07 '17 at 00:26
37

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.
Vlad Frolov
  • 7,445
  • 5
  • 33
  • 52
  • 9
    I wouldn't recommend this. It destructively modifies the history so it might confuse people that have branches based off of this commit, and the `--amend` flag also might not change the `HEAD` commit in some cases. – Nick McCurdy Apr 29 '16 at 06:49
  • 7
    I find it fine for the rare occasions when you need only BUMP webhooks for a PR. Nobody should really branch out of pull-requests, so nobody will rely on the exact commit id. – Vlad Frolov May 08 '16 at 10:21
  • 4
    go for `git push --force-with-lease origin pr-branch` so you don't accidentally nuke someone else's changes – binarymason Aug 29 '16 at 13:04
20

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"
lampslave
  • 1,431
  • 1
  • 15
  • 20
16

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"
 }
Sam Brightman
  • 2,831
  • 4
  • 36
  • 38
12

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).

iconoclast
  • 21,213
  • 15
  • 102
  • 138
  • 2
    Thanks. For me, it's the best response because a trigger build changes also build's ID, not with a simple rebuild (via the button). If you use Travis' id in your scripts, it's important to know. – Karima Rafes Aug 05 '18 at 17:04
  • 2
    This needs to be higher up – Gillespie Jul 29 '19 at 22:34
8

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.

Greg Bray
  • 14,929
  • 12
  • 80
  • 104
  • I do not understand the update note. From the command it seems like you can define what job to restart. So the question is about to trigger a job, presumingly most people would want to do this if their commit already triggered but they want to test it again to so ... Oh I guess you cant deactivate commit branch triggers and manually build HEAD. – redanimalwar Oct 24 '16 at 16:39
  • @redanimalwar a common use-case is forcing a CI build when it fails to detect changes or is in a quiet period. – Sam Brightman Nov 15 '16 at 17:11
4

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.

Suzanne Soy
  • 3,027
  • 6
  • 38
  • 56
viperguynaz
  • 12,044
  • 4
  • 30
  • 41
4

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".

banzaiman
  • 2,631
  • 18
  • 27
  • This doesn't work if you have no write access/colaborator to the repository and want to rerun build for your own pull request. I don't see that option. And when trying the Travis CLI, it says `build #xxxx has been restarted` but if you look in the webpage you don't see any build happening – Alex Bitek Jan 03 '18 at 11:31
1

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

Frazer Kirkman
  • 1,003
  • 1
  • 14
  • 23
1

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
grooveplex
  • 2,492
  • 4
  • 28
  • 30
1

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 ;-)

dan
  • 1,144
  • 12
  • 17
1

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.)

XenoAmess
  • 345
  • 1
  • 3
  • 12
-1

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

Punit Naik
  • 515
  • 7
  • 26
  • No, PLEASE don't leave garbage pull requests, it's annoying. Just push new commit(s) to your branch (for example you can change the commit date: git commit --amend --date=now && git push -f). – intgr Jul 06 '18 at 09:48