Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start Travis CI deploy only when tag name matches a regex

I want to kick off an npm deployment when a tag, that looks like a semantic version, is pushed, e.g. v1.2.3. I see that the tag name is in the TRAVIS_TAG environment variable and that I can specify an on: condition, which "can be any Bash condition". I have no idea what to write here and how to debug it.

- provider: npm on: tags: true all_branches: true condition: ???

Ideally, I would like to not bother with Bash at all - I would like the condition to execute a Node.js script and then decide whether to deploy or not depending on the node exit code. How can I do that?

like image 524
Stefan Dragnev Avatar asked Jul 10 '14 14:07

Stefan Dragnev


2 Answers

Simplest way would still be with bash, this example will deploy only if tag name matches the regex "release.*":

on:
    tags: true
    all_branches: true
    condition: "$TRAVIS_TAG =~ ^release.*$"

Check out this link for more info on travis environment variables: http://docs.travis-ci.com/user/ci-environment/#Environment-variables

like image 71
eshirazi Avatar answered Oct 20 '22 02:10

eshirazi


eshizari's answer didn't work for me. This is the approach that I'm using instead:

on:
  all_branches: true
  condition: $TRAVIS_TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+
like image 6
pomber Avatar answered Oct 20 '22 03:10

pomber