如何仅在标记的分支上运行 gitlab-ci.yml 作业? [英] How to run a gitlab-ci.yml job only on a tagged branch?

查看:28
本文介绍了如何仅在标记的分支上运行 gitlab-ci.yml 作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅在标记的 Master 分支上运行 .gitlab-ci.yml 作业?

How do I run a .gitlab-ci.yml job only on a tagged Master branch?

job:
  script:
  - echo "Do something"
  only:
  - master
  - tags

如果存在以下任一条件,上述代码将运行:主分支或标记提交.

The above code will run if either condition exists: a Master branch or a tagged commit.

我的目标是为生产部署运行这个,但它要求它位于主分支上并且它被标记(带有版本).否则,我将有另一份工作,如果它缺少标签,它将推动登台.

My goal is to have this run for a production deploy, but it would require that it be on the Master branch and that it be tagged (with a version). Otherwise, I'll have another job that will push to staging if its missing a tag.

推荐答案

此行为将在版本 12.

未决问题最近更新:

Jason Lenny @jlenny 将标题从 {-Update .gitlab-ci.yml 更改为支持构建条件的连接逻辑 - } 到连接逻辑对于构建条件 MVC · 2 天前

Jason Lenny @jlenny changed title from {-Update .gitlab-ci.yml to support conjunction logic for build conditions-} to Conjunction logic for build conditions MVC · 2 days ago

Jason Lenny @jlenny 将里程碑更改为 12.0 · 2 天前

Jason Lenny @jlenny changed milestone to 12.0 · 2 days ago

(手指交叉)

一种解决方案是使用 except 关键字排除所有分支,结合 only 在标签上运行,这样您就可以只在标签上运行管道在主分支中:

A solution is to use the except keyword to exclude all the branches, in conjunction with only to run on tags, in this way you run your pipeline only on tag in master branch:

  only:
    - tags
  except:
    - branches

我正在使用版本 11.3.4

这篇关于如何仅在标记的分支上运行 gitlab-ci.yml 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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