Execute job only on specific commit message never triggers

I would like to execute a travis stage only on specific commit message (finally on a text tag in a commit message, but let’s simplify for now). Travis allows conditional execution using if statement (and I prefer to use that, because of the structure of my travis file). Travis documentation mentions 2 variables that could be used to get commit message: commit_message and TRAVIS_COMMIT_MESSAGE I tried using both of them. In these cases:

- stage: Deploy
  if: commit_message = "deploy" AND type = push


- stage: Deploy
  if: $TRAVIS_COMMIT_MESSAGE = "deploy" AND type = push

the stage is executed always, no matter what is the content of the commit message.

In that case:

- stage: Deploy
  if: env(TRAVIS_COMMIT_MESSAGE) = "deploy" AND type = push

The stage is never executed, no matter what is the content of the commit message.

I also tried adding conditions: v1 in the root of the .travis file, but with no effect. It seems like comparison operator is not working as expected (especially in first two cases - how can it always be true if strings are not equal??).
Why is comparing commit message not working as expected?

As per Conditional Builds, Stages and Jobs - Travis CI, the conditional stage syntax is:

stages:
  - name: deploy
    if: <condition>

Sorry for not making that clear, but stages are part of a job in my case:

jobs:
  include:
    - stage: Deploy
      if: commit_message = "deploy" AND type = push

Also if I only change the condition to checking for branch name, it works as expected:

- stage: Deploy
  if: branch = master AND type = push

WFM:

Correct message: Travis CI - Test and Deploy with Confidence

Wrong message: Travis CI - Test and Deploy with Confidence, commit f0d961f

Check for any warnings/errors on the Config tab and/or use https://config.travis-ci.com/explore to verify your .travis.yml.

1 Like