Today I learned about git tags, and how to use them to control job triggering in gitlab ci.
Git tags are ref’s that point to specific points in Git history. There are two types: Lightweight which act as bookmarks for specific commits (can be thought of as private) and Annotated which stores extra meta data like tagger’s name and email address.
git tag <tagname> #lightweight
git tag -a <tagname> -m <tag_message> #annotated
To trigger jobs according to tags we either use only:
/except:
or job(or workflow) rules.
Run the compile job for tagged commits only
stages:
- compile_stage
compile:
stage: compile_stage
image: rekka/tectonic
only:
- tags
script:
- tectonic Resume-fr.tex
artifacts:
paths:
- Resume-fr.pdf
Run the pipline only for tagged commits with a version number having a pair patch number.
stages:
- compile_stage
workflow:
rules:
- if: '$CI_COMMIT_TAG =~ /v\d+\.\d+\.\d*[02468]/'
compile:
stage: compile_stage
image: rekka/tectonic
script:
- tectonic Resume-fr.tex
artifacts:
paths:
- Resume-fr.pdf
More on tags - atlassian
only/except - gitlab ci docs
rules - gitlab ci docs
Semantic versionning - semver
Predifined env variables - gitlab ci docs
Variable matching syntax - gitlab ci docs