Travis CI inline Bash Script

Viewed 1305

I have the following Travis CI yml file snippet:

script:
  - if [ $TRAVIS_BRANCH == "master" ]; then
      sbt clean coverage test coverageReport docker:publishLocal;
    fi
  - if [ $TRAVIS_BRANCH == "/^develop-.*$/" ]; then
      sbt clean coverage test coverageReport;
    fi

It sort of works, but I could not understand the logs that it produces. It is sort of misleading. Here is the log from the build server:

[success] Total time: 22 s, completed Aug 8, 2017 5:29:28 PM

The command "if [ $TRAVIS_BRANCH == "master" ]; then sbt clean coverage test coverageReport docker:publishLocal; fi" exited with 0.
0.00s

$ if [ $TRAVIS_BRANCH == "/^develop-.*$/" ]; then sbt clean coverage test coverageReport; fi

The command "if [ $TRAVIS_BRANCH == "/^develop-.*$/" ]; then sbt clean coverage test coverageReport; fi" exited with 0.

How could anything that did not run exit with a code 0? I would have rather expected it to just say, it skipped that script. What do you guys think?

1 Answers
"if [ $TRAVIS_BRANCH == "master" ]; then sbt clean coverage test coverageReport docker:publishLocal; fi" 

in its entirety is what travis uses as the command for the step. Even if the 'true' branch of the if statement is not executed, travis still executed a command successfully, hence the exit 0. If you want message for skipped configurations, you would have to add them yourself

  - if [ $TRAVIS_BRANCH == "master" ]; then
      sbt clean coverage test coverageReport docker:publishLocal;
    else
      echo "Skipped"
    fi

Additionally, your second check is is maybe not doing what you want. Using the =~ operator enables Regex matching, == may only use glob pattern-matching, AFAIK.

Related