GitLab CI-添加标签时避免构建 [英] GitLab CI - avoid build when adding tag

查看:308
本文介绍了GitLab CI-添加标签时避免构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我添加git标签时,如何防止gitlab ci管道被触发?我在本地运行此命令(而不是在gitlab-ci作业中)

How do I prevent a gitlab ci pipeline being triggered when I add a git tag? I'm running this command locally (as opposed to within a gitlab-ci job)

git tag -a "xyz"

,然后按下标签;这触发了各种管道.我想排除其中一些管道的运行.

and then pushing the tag; and this triggers various pipelines. I want to exclude some of those pipelines from running.

我正在尝试解决诸如

I'm trying variations on ideas from questions such as this; that question is using only, I'm wanting to exclude, so I'm trying except. The answers there have two variants, one with refs one without.

build:  
  # ... my work here ...  
  except:
    - tags


build:  
  # ... my work here ...  
  except:
    refs:
      - tags

似乎都没有任何作用;我添加标签,构建仍然会发生.

Neither seem to have any effect; I add a tag, the build still happens.

在这里,我的理解可能完全不正确,因为标签一词似乎具有三种可能的含义,并且在阅读文档或示例时,我并不总是确定哪个含义适用:

My understanding may be completely awry here as there seem to be three possible meanings of the word tags and when reading docs or examples I'm not always sure which meaning is applicable:

  1. 使用 git标签
  2. 应用的Git标签
  3. Gitlab CI标签,用于确定哪些跑步者选择工作
  4. 提交的 ref 标识符,用于通过REST API触发管道.这通常是分支名称,但可以是git标签.
  1. Git tags applied using git tag
  2. Gitlab CI tags used to determine which runners pick a job
  3. The ref identifier of a commit used to trigger a pipeline via the REST API. This is usually a branch name, but could be a git tag.

我有兴趣控制第一种情况.到目前为止,从注释中似乎可以清楚地看出,除外:-tags"与我的情况无关,那么有什么方法行得通吗?

I'm interested in controlling what happens if the first case. It does seem clear from comments so far that "except: -tags" is not relevant to my case, so is there any approach that does work?

推荐答案

Except tags正是您要跳过标记构建的原因.

Except tags is exactly what you should use if you want to skip build for tags.

您需要确保了解提交vs分支vs标签

为了说明将标记的提交推送到gitlab时会发生什么,我做了如下操作:

To illustrate what happens when you push tagged commit to gitlab I did as follows:

  1. 使用以下内容创建了.gitlab-ci.yml:

tests_always_run:
    script:
      - echo I should always execute
tests_except_tags:
    script:
      - echo I skip tagged triggers
    except:
      - tags

  1. 提交更改,标记提交并使用--follow-tags推送以确保标记也传播到服务器:
  1. Commited changes, tagged commit and pushed with --follow-tags to make sure tag is also propagated to server:

git add .gitlab-ci.yml
git commit -m 'my great yml with except tags'
git tag -a "abc" -m "Test tag"
git push --follow-tags

说明的结果:

如果您要跳过CI以便进行选定的提交,则可以使用 git push -o ci.skip ,受本文

If you want to skip CI for selected commit then you could use git push -o ci.skip, inspired by this article

这篇关于GitLab CI-添加标签时避免构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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