A part of custom deploy condition is ignored

Hi all,
this is my yml file

   language: scala

jdk:
  - openjdk8

before_install:
  - chmod +x build.sh

install:
  - pyenv install 3.6.1
  - pyenv global 3.6.1
  - pip install --upgrade pip

env:
  - DEPLOY_DEST=staging

services:
  - docker

branches:
  only:
    - master
    - /^v[0-9].*$/

script:
  - ./build.sh test;

before_deploy:
  - pip3 install awscli

deploy:
  - provider: script
    skip_cleanup: true
    script: bash ./build.sh deploy_staging $TRAVIS_TAG
    on:
      tags: true
      all_branches: true
      condition: $TRAVIS_TAG =~ ^v[0-9].*$ && $DEPLOY_DEST=staging
  - provider: script
    skip_cleanup: true
    script: bash ./build.sh deploy_production $TRAVIS_BRANCH
    on:
      tags: false
      all_branches: true
      condition: $TRAVIS_BRANCH =~ ^v[0-9].*$ && $DEPLOY_DEST=production

Problem i’m having is: when the branch name starts e.g with v1… after pull request is closed, it deploys to production. I’ve read in documentation that it will deploy when a single bash condition evaluates to true. I tried many different options with conditions, but for some reason it’s always ignored and every time i close pull request it deploys production. If I set branch: /^v[0-9].*$/ than it will not deploy production
Idea is next:

  • Draft a new release on github deploys staging with version e.g v1.0.1
  • Triggering custom build on Travis-CI UI with branch:v1.0.1 env: DEPLOY_DEST=production deploys production

Could you please tell me what I’m doing wrong?

This is one of bash's all-too-familiar gotchas with significant spaces:

$ TRAVIS_BRANCH=v1.0.1
$ set -x
$ if [[ ( $TRAVIS_BRANCH =~ ^v[0-9].*$ ) && ( $DEPLOY_DEST==production ) ]]; then echo foo; else echo bar; fi
+ [[ v1.0.1 =~ ^v[0-9].*$ ]]
+ [[ -n ==production ]]
+ echo foo
foo

As you can see, without spaces around the equal sign, the 2nd condition is not evaluated the way you expect it to.

You need to write the condition as:

$TRAVIS_BRANCH =~ ^v[0-9].*$ && $DEPLOY_DEST == production
Imprint