Running a branch conditional

I working on a project (same project), and im trying to deploy conditionals for branches, example: anything merged into the develop branch, I want to end up on https://dev.mysite , but anything merged into the master branch, I want deployed to https://www.mysite.com .

language: csharp
mono: none
sudo: required
dist: xenial
dotnet: 2.2
branches:
only:
    - master
    - develop
before_script:
- chmod -R a+x scripts
script:
- "./scripts/docker-publish-travis.sh"
after_success:
- "./scripts/after-success.sh"
notifications:
email:
    on_success: never
    on_failure: always

is it even possible to add a conditional to the above .travis.yml file so that if the branch is develop , a different script is run?

develop branch

script:
    - "./scripts/docker-publish-travis-develop.sh"

master branch

same path as develop.sh

Hey,

Seems like you’re over complicating things. A simple if/else bash script would solve this.

You should try calling the same script for both develop and master using ( ./scripts/docker-publish-travis.sh ), and maybe have this script do something else based on the $TRAVIS_BRANCH environment variable?

if [[ "$TRAVIS_BRANCH" == "master" ]]; then
  # Push to the master branch here
else
  # Push to the develop branch here
fi

Remember to give it permissions, seems to me this would be the easiest fix. Good luck.

Happy building!
Montana Mendy

1 Like
Imprint