Sammy I.
Sammy I.

Reputation: 2735

Trigger a TravisCI build stage conditionally?

I am using TravisCI's Build Stages to separate my job to two stages:

  1. Build and test on multiple environments.
  2. Build and deploy if stage 1 pass.

And I want to Travis to run the jobs on commits to two GitHub branches, master and dev, and pull requests to master and dev. However, I only want to run the stage two when a commit to master happens.

Is there a way to completely ignore stage 2 in commits to branches that are not master, and on pull requests?

This is what my .travis.yml looks like at the time of writing this: https://github.com/SammyIsra/photostream-react/blob/c354a62c3cc963b345a5c2fb95658c90ddc39d21/.travis.yml

Update: this seems to not be possible as of yet. However, the TravisCI team may be working on something like that, as of this comment on the Build Stages feedback board. Whenever I learn that it was added as a feature, or that it will definitely not be possible ever, I will change this question.

Upvotes: 3

Views: 785

Answers (1)

ocean
ocean

Reputation: 1350

There doesn't seem to be a way to ignore specific branches when triggering jobs in the build stages section, however it looks like there's a way to only fire your deployments on pushes to master.

In your build stage script section, you could wrap the npm run build command in a quick Bash if statement to test the environment variable which shows what branch you're on:

if [ TRAVIS_BRANCH == "master" ]; then npm run build; fi

Then, in your Surge deploy section, you can restrict the deployment to a particular branch with:

deploy:
    ...
    on: master

And basically the same for the NPM deployment:

deploy:
    ...
    on:
        branch: master

Note: I've not tried any of this myself, so it may or may not work in combination with the new build stages functionality.

Upvotes: 1

Related Questions