'how to trigger gitlab pipeline by tags

How to trigger a GitLab CICD pipeline whenever a tag like below gets created? How can I make it in regular expression for all future tags based on the same format?

Tag to trigger the pipeline: 2021.08.31.DEVRELEASE.0001

Where DEVRELEASE is the static keyword, rest of the keywords would change.



Solution 1:[1]

You can use rules and if keywords to define your tag's regex. You can use the following snippet and customize the regex to match your desired tag:

publish:
  stage: publish
  image: ...
  script:
    - ...
  rules:
    # Runs only when a tag with 'X.Y.Z.DEVRELEASE.A' pattern is created
    - if: '$CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+\.DEVRELEASE\.\d+$/'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1