Trigger a Travis-CI rebuild without pushing a commit?

后端 未结 16 2130
长发绾君心
长发绾君心 2020-12-12 08:21

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 co

相关标签:
16条回答
  • 2020-12-12 08:53

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

    0 讨论(0)
  • 2020-12-12 08:59

    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"
     }
    
    0 讨论(0)
  • 2020-12-12 09:02

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

    0 讨论(0)
  • 2020-12-12 09:05

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

    0 讨论(0)
  • 2020-12-12 09:07

    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.

    0 讨论(0)
  • 2020-12-12 09:08

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

    0 讨论(0)
提交回复
热议问题