Thomas Dondorf
Thomas Dondorf

Reputation: 25240

Travis deploy stage not running with condition if: branch = master AND tag IS present AND type = push

My Travis file contains two stages:

I pushed a tagged commit to the master (so all three conditions should be met), but after the test stage finishes successfully, the deploy stage is not started.

Here are other (potentially important) parts of my .travis.yml file:

language: node_js

node_js:
  - '8'
  - '9'
  - '10'
  #- '11' # Runs the coverage report (added below)

before_script: npm run build
script:
  - npm run lint
  - npm run coverage

jobs:
  include:
    - stage: test
      node_js: '11'
      after_success: 'cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js'
    - stage: deploy
      node_js: '11'
      script: skip
      deploy:
        provider: npm
        # ...

stages:
  - test
  - name: deploy
    if: branch = master AND tag IS present AND type = push

Upvotes: 1

Views: 1446

Answers (1)

Thomas Dondorf
Thomas Dondorf

Reputation: 25240

I found it out myself after adding these lines to my travis file:

echo "$TRAVIS_EVENT_TYPE" # result: push
echo "$TRAVIS_TAG"        # result: v0.14.0
echo "$TRAVIS_BRANCH"     # result: v0.14.0

So the branch is set to the tag name, when a tag is set. I also found this hint on the docs for environment variables:

Note that for tags, git does not store the branch from which a commit was tagged.

Strangely, you can still check for the branch in the deploy condition. So this worked for me:

  # ...
  deploy:
    provider: npm
    # ...
    on:
      tags: true
      branch: master

stages:
  - test
  - name: deploy
    if: type = push

Upvotes: 1

Related Questions