Travis: different `script` for different branch?
Travis-CI always creates builds based on the .travis.yml
in the branch you are pushing. As a solution, you could thus maintain different .travis.yml
files in the different branches.
If you regularly merge between the branches, this could however lead to inadvertent changes between the branches (if you merge the changes of the .travis.yml
of one branch over to the other). If this is a concern, your solution is probably safer.
To ensure that only specific branches (e.g. develop
and master
) are built, you can whitelist the branches in your .travis.yml
.
When using your existing solution, you could simplify your travis.yml
script though. It probably makes sense to move the logic for selecting the correct deploy target into your ci/deploy.rb
script (or even add a separate wrapper script which you call from the .travis.yml
). That way, you have only one script
line in your .travis.yml
which don't even needs to change if you change deployment targets.
Alternatively, to ensure you have no failing tests with your existing structure, you could even use something like this:
script:
- if [ "$TRAVIS_BRANCH" = "develop" ]; then ./ci/deploy.rb envdev.tld; fi
- if [ "$TRAVIS_BRANCH" = "master" ]; then ./ci/deploy.rb envprod.tld; fi
Seems that the best solution now is to use stages. You can have something like:
stages:
- name: deploy
# require the branch name to be master (note for PRs this is the base branch name)
if: branch = master
See Travis documentation for more detail regarding stages.