Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if master branch pushed with a tag under Travis?

Tags:

yaml

travis-ci

I want to do some additional testing on Travis, but I just want to check if the commit has directly pushed to master branch and the commit comes with a Tag ? Is there anyway to check for tag on Travis inside the yaml file ?

like image 560
Soheil Avatar asked Jan 12 '15 06:01

Soheil


2 Answers

During build travis set some useful environment variable, which can be used in your script also in yml file. https://docs.travis-ci.com/user/environment-variables#Default-Environment-Variables

Example:

script:
    - if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then something on direct push to master; fi
    - if [ ! "$TRAVIS_PULL_REQUEST" = "false" ]; then something on pull request; fi
    - if [ -n "$TRAVIS_TAG" ]; then something when tag set; fi

Travis run commands in order like defined in script tag, so you can build some logic on build which depends on environment variables

like image 139
Slawomir Jaranowski Avatar answered Nov 05 '22 20:11

Slawomir Jaranowski


As Slawomir Jaranowski described, travis provides environment variables describing the commit.

Travis’ default convenience environment variables will tell you either the branch name or the tag. Travis does not give you the branch name in tagged builds, but you can get it for yourself if you need both the branch and the tag.

like image 28
Aryeh Leib Taurog Avatar answered Nov 05 '22 20:11

Aryeh Leib Taurog