GitLab CI/CD pipeline no tags supplied means SANITY module should run automatically

Viewed 29

I am trying to run my test suit using GitLab with annotations so suppose i have 4 Scenario defined out of which two are for regression and 2 are sanity but when pass tag named regression it run my regression hook now, I want a solution if I don't pass any tag it should run sanity hook

stages:
    - build

cucumber_test:
    stage: build
    tags: [regression , sanity]
    allow_failure: false
    script:
       - mvn "clean" "test" "-Dcucumber.filter.tags=@%Tag%"
      

    rules:
    - if: '$Tag == "reg"'
      allow_failure: true 

    artifacts:
        paths:
          - Report
        when: always

enter image description here

1 Answers

Because your only rule requires a specific value for Tag, the job will only be present in that circumstance.

I want a solution if I don't pass any tag it should run sanity hook

What you probably want to do here is set a default value defined in variables:. Additionally, you need to add a default rule to make sure the job runs even when the Tag value is not reg.

variables:
  Tag: "sanity"  # the default if none is provided manually
rules:
  - if: '$Tag == "reg"'
    allow_failure: true
  - when: on_success  # run this job normally, even when $Tag is not "reg"
Related