[英]How to read labels in Gitlab CI script
I have a few use cases in my Gitlab setup I would like to be able to support:我希望能够支持的 Gitlab 设置中有一些用例:
Is this possible with Gitlab, and if so, how? Gitlab 是否可以做到这一点,如果可以,怎么做?
I've tried experimenting with CI_MERGE_REQUEST_LABELS, but it doesn't seem to be able to read that as an env var from within the script.我尝试过使用 CI_MERGE_REQUEST_LABELS 进行试验,但它似乎无法从脚本中将其作为环境变量读取。
You have to use merge request pipelines for the CI_MERGE_REQUEST_LABELS
variable (and other MR-related variables) to be present as documented in predefined variables .您必须为CI_MERGE_REQUEST_LABELS
变量(以及其他与 MR 相关的变量)使用合并请求管道,才能按照预定义变量中的说明出现。
You could use a rules:
clause to skip jobs.您可以使用rules:
子句跳过作业。 Something like就像是
build:
rules: # only run this job if the regex pattern does not match
- if: $CI_MERGE_REQUEST_LABELS !~ /skip_build/
You can also do this on any other kind of predefined (or user-defined) variable, like branch name, commit messages, MR titles, etc. Whatever works for you.您还可以对任何其他类型的预定义(或用户定义)变量执行此操作,例如分支名称、提交消息、MR 标题等。任何适合您的。
For example, a built in feature of GitLab is that if your commit message contains [ci skip]
it will prevent the pipeline from running.例如,GitLab 的一个内置特性是,如果您的提交消息包含[ci skip]
,它将阻止管道运行。 You could implement similar functionality for your jobs and/or pipelines through rules:
or workflow:rules:
.您可以通过rules:
或workflow:rules:
为您的作业和/或管道实现类似的功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.