Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit_message condition seems to be always true #32

Open
notrev opened this issue Sep 9, 2021 · 0 comments
Open

commit_message condition seems to be always true #32

notrev opened this issue Sep 9, 2021 · 0 comments

Comments

@notrev
Copy link

notrev commented Sep 9, 2021

Hello.

I use Travis Enterprise and am facing an issue when trying to run specific stages based on conditions.

What I want:

  • if the commit message contains the word #ci-test, run stages: build and test.
  • if a pull request is updated or created, run stages: build, test and deploy to dev.
  • if a push is made to the master branch, run stages: build, test and deploy to prod.

My (simplified) .travis.yml file is:

group: vm
services:
  - docker

git:
  depth: false

env:
  global:
    - MYVAR="VARVALUE"

jobs:
  include:
    - stage: "build"
      if: type = pull_request OR commit_message =~ /#ci-test/
      script: build_docker_image.sh

    - stage: "tests"
      if: type = pull_request OR commit_message =~ /#ci-test/
      script: run_tests.sh

    - stage: "deploy to dev"
      if: type = pull_request
      script: do_the_deploy_to_dev_magic.sh

    - stage: "deploy to production"
      if: type = push AND branch = master
      script: do_the_deploy_to_prod_magic.sh

The problem is that it doesn't matter if #ci-test is present, or not, in the commit message, the build and tests stages are always run in any push, and are duplicated for pushes in PRs. I have made several tests with different checks, even using !~ instead of =~, but they always seem to be true.

I have also tested the travis-condition cli tool and the evals work as expected: returning false if the string is not present in the commit message and true if the string is present. But it doesn't seem to be this way in Travis.

An example of a test I have made:

I have a branch named test/ci-pull-triggers (wrote it wrong and didn't want to change it), that is not related to any pull requests. So, it should trigger only builds for pushes that contain #ci-test in them. With the .travis.yml above (slightly modified to run only tests), every push triggers a build in Travis.

A screenshot of details of one of the builds:
Screenshot from 2021-09-09 16-34-46
Note that the commit message wip: test build triggers v23 has no #ci-test in it.

The job config:

{
  "group": "vm",
  "language": "python",
  "services": [
    "docker"
  ],
  "git": {
    "depth": false
  },
  "jobs": {
    "include": [
      {
        "stage": "Build docker image",
        "if": "type = pull_request",
        "script": [ HIDDEN ]
      },
      {
        "stage": "Run Tests",
        "if": "type = pull_request OR commit_message =~ /#ci-test/",
        "script": [ HIDDEN ]
      },
      {
        "stage": "Build and deploy to dev",
        "if": "type = pull_request",
        "script": [ HIDDEN ]
      },
      {
        "stage": "Build and deploy to production",
        "if": "type = push AND branch = master",
        "script": [ HIDDEN ]
      }
    ]
  },
  "global_env": "HIDDEN",
  "os": "linux",
  "dist": "trusty",
  "if": "type = pull_request OR commit_message =~ /#ci-test/",
  "script": [ HIDDEN ],
  "stage": "Run Tests"
}

Am I doing something wrong? Is Travis Enterprise using an old version of travis-condition? Is there something wrong with Travis conditions?

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant