script:
- echo hello cicd
rules:
- if: "($CI_PIPELINE_SOURCE == 'pipeline' || $CI_PIPELINE_SOURCE == 'web') && $CI_COMMIT_TAG != null && $CI_COMMIT_BRANCH == 'main' "
since above rule with CI_COMMIT_TAG
is only triggered when tag
is pushed to gitlab, one can use the below
to execute commands only when a commit is tagged via pipeline.
script:
- |
if [[ $(expr length $(git describe --exact-match --tags)) > 0 ]] && [[ $CI_COMMIT_BRANCH = 'main' ]]; then
echo $CI_COMMIT_SHORT_SHA is tagged as $(git describe --exact-match --tags)
echo hello cicd
else
echo no tags found for commit $CI_COMMIT_SHORT_SHA
fi
rules:
- if: "($CI_PIPELINE_SOURCE == 'pipeline' || $CI_PIPELINE_SOURCE == 'web')"
working example of multi-project gitlab cicd pipeline:
https://gitlab.com/pangyuteng/hello-world-app
https://gitlab.com/pangyuteng/hello-world-lib