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

如何仅在带标签的分支上运行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

如果存在以下两种情况,则上述代码将运行:Master分支或带标记的提交.

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

我的目标是针对生产部署运行此程序,但是这将要求它在Master分支上,并且必须对其进行标记(带有版本).否则,如果缺少标签,我将进行另一项工作,将其升级.

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