Apoorva Manjunath
Apoorva Manjunath

Reputation: 855

Travis conditional deployment: deploy script with regexp for branch skipped with error `branch not permitted`

I have specified multiple deploy script providers. One which is expected to run, but skipped is:

- provider: script
  skip_cleanup: true
  script: curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --skip-publish
  verbose: true
  on:
    condition: "$TRAVIS_OS_NAME = linux"
    branches:
      only:
      - /^release\/.*$/
    go: 1.11.x

Can someone point why the release branch deploy is skipped in this case? I want the first deploy to run on linux and release branches only like: release/2.1.5.

Travis build: https://travis-ci.org/leopardslab/dunner/jobs/560593148

Travis Config file: https://github.com/leopardslab/dunner/blob/172a4c5792b0a8389556cc8ee4f690dc73fafb6e/.travis.yml

Upvotes: 0

Views: 1041

Answers (1)

Apoorva Manjunath
Apoorva Manjunath

Reputation: 855

To run the deploy script conditionally, say only on branches matching a regular expression like release branches as ^release\/.*$, use condition field and concatenate multiple conditions using &&. The branch or branches field does not support regexp.

If branch or branches field is not specified, travis assumes its on master branch(or default branch). So be sure to include all_branches: true line in travis config.

You can access current branch name using travis env variable $TRAVIS_BRANCH.

deploy:
  - provider: script
    script: bash myscript.sh
    verbose: true
    on:
      all_branches: true
      condition: $TRAVIS_BRANCH =~ ^release\/.*$ && $TRAVIS_OS_NAME = linux

Upvotes: 1

Related Questions