0

I want to run a Gitlab pipeline stage after pushing a commit on the 'master' branch and a directory named 'tests' exists in the project root. Here is the relevant snippet from .gitlab-ci.yaml that defines the stage and its rules:

    stage: test
    image: python:3.10.3-bullseye
    rules:
        -   if: $CI_COMMIT_BRANCH == "master"
            exists:
                - tests
    before_script: *setup-python
    script:
        - pip install -e .[dev]
        - pytest tests/

However, after a commit on the master branch, it remains disabled. I'm a bit fuzzy on the syntax, despite reading the docs carefully. Does anyone know how to achieve what I'm after?

Lawrence I. Siden
  • 9,191
  • 10
  • 43
  • 56

1 Answers1

1

As in https://docs.gitlab.com/14.10/ee/ci/yaml/#rules,

Rules are evaluated when the pipeline is created, and evaluated in order until the first match. When a match is found, the job is either included or excluded from the pipeline, depending on the configuration.

Try,

stage: test
image: python:3.10.3-bullseye
rules:
  - if: $CI_COMMIT_BRANCH != "master"
    when: never
  - exists:
    - tests/**/*.py
before_script: *setup-python
script:
  - pip install -e .[dev]
  - pytest tests/
dragsu
  • 111
  • 1
  • 1
  • 10