问题
I would like to build docker image on master branch only when release tag is set. This is my .gitlab.ci
:
build:
rules:
- if: '$CI_COMMIT_TAG != null && $CI_COMMIT_REF_NAME == "master"'
script:
- echo "Building $IMAGE:${CI_COMMIT_TAG}"
This does not work, I merged to master and release tag, but the build job did not even start.
I also tried with only
section:
build:
only:
- master
- tags
script:
- echo "Building $IMAGE:${CI_COMMIT_TAG}"
This run everytime, even when CI_COMMIT_TAG
does not exists. Is there a way, how to force to run job only if CI_COMMIT_TAG
exists on master
branch?
回答1:
With
build:
only:
- tags
you can run a job only when a tag was set (or pushed). If you have master
in there, it runs on every commit on master. Without master
it only runs after setting a tag.
来源:https://stackoverflow.com/questions/60722228/gitlab-ci-run-job-on-master-with-release-tag-only