Gitlab CI仅在具有发布标签的master上运行作业 [英] Gitlab ci run job on master with release tag only

查看:509
本文介绍了Gitlab CI仅在具有发布标签的master上运行作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当设置了release标签时,我才想在master分支上构建docker映像.这是我的.gitlab.ci:

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}"

这不起作用,我合并到master和release标签,但是构建作业甚至没有开始.

This does not work, I merged to master and release tag, but the build job did not even start.

我也尝试过only部分:

build:
  only:
    - master
    - tags
  script:
    - echo "Building $IMAGE:${CI_COMMIT_TAG}"

每次都运行,即使CI_COMMIT_TAG不存在也是如此.有没有办法仅在master分支上存在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?

推荐答案

使用

build:
  only:
    - tags

仅当设置(或按下)标签时,您才能运行作业.如果其中有master,它将在master的每次提交上运行.如果没有master,则仅在设置标签后运行.

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.

这篇关于Gitlab CI仅在具有发布标签的master上运行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆