Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set "deploy on branch", with branch name matching regex a expression using Travis CI?

Tags:

travis-ci

When we cut release branches for our product, we version them like this:

release/x.x.x

Is there a way on travis.yml file to set deploy on branch matching a regex pattern?

travis.yml snippet:

provider: script
script: bash dockerbuildandpush.sh
on:
  branch: /^release\/.*$/

The above-mentioned snippet does not work. Any help would be appreciated.

like image 952
RJ Mohammad Avatar asked Dec 06 '25 04:12

RJ Mohammad


1 Answers

Figured it out. Leaving it out there for anyone else trying to do the same thing.

provider: script
script: bash dockerbuildandpush.sh
on:
  all_branches: true
  condition: ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} =~ ^release\/.*$

Explanation for ${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} can be found here: https://github.com/travis-ci/travis-ci/issues/6652

https://graysonkoonce.com/getting-the-current-branch-name-during-a-pull-request-in-travis-ci/

like image 66
RJ Mohammad Avatar answered Dec 09 '25 14:12

RJ Mohammad