Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Travis-CI for pull requests

Tags:

travis-ci

I have a project that uses Travis-CI to build and rsync a static website. I use the following to ensure that this only occurs in master.

branches:
  only:
    - master

However, when someone makes a pull request on the repository, Travis-CI prospectively merges that branch into master and does the build and rsync, meaning that anyone could replace the contents of my website with anything by submitting a pull request.

Is there a way to prevent Travis-CI from attempting to build pull requests?

like image 887
tbekolay Avatar asked Jan 12 '14 15:01

tbekolay


People also ask

How do I disable Travis CI?

You should see a My repositories label followed by a plus sign (i.e. + ). Click on that plus sign (i.e. + ). It will lead you to a page listing all your Github repositories with an on/off toggle beside each one. Just put the toggle to "off" for the repositories you don't want in Travis CI.

What is a pull request in CI?

Pull requests are a formalized way of reviewing and merging a proposed set of changes to a codebase.

What is a pull request Build?

A Pull Request Build is a build of a non-production branch of your site. Pull Request Builds are intended to show the impact of potential code changes before merging those changes into your production branch.


1 Answers

You can find out if Travis is checking a pull request by checking the environment variable TRAVIS_PULL_REQUEST. It contains:

The pull request number if the current job is a pull request, "false" if it's not a pull request.

See also the docs.

You can change your command to check this and only build on non-pull requests with

if [[ $TRAVIS_PULL_REQUEST == 'false' ]]; then your-command; fi

To avoid the scenario described by @ruslo, you can (and should!) use encrypted environment variables for building the rsync connection. These are not available with pull requests (at least with those that come from a fork), so that everything's safe here:

Please note that secure env variables are not available for pull requests from forks. This is done due to the security risk of exposing such information in submitted code. Everyone can submit a pull request and if an unencrypted variable is available there, it could be easily displayed.

(The reasons stated in the docs are different, but the mechanism would work here as well.)

like image 194
krlmlr Avatar answered Oct 18 '22 15:10

krlmlr