Gitlab ci run job on master with release tag only

情到浓时终转凉″ 提交于 2020-12-06 06:52:46

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!