覆盖外部gitlab.yml文件

发布于 2025-02-04 08:25:33 字数 503 浏览 1 评论 0原文

假设我们有一个.gitlab-ci.yml文件,该文件在common.gitlab-ci.complete.yml file:

include: common.gitlab-ci.complete.yml

假设common.gitlab-ci中。

stages:
  - build
  - unit-test
  - mutation-test

​-Test 阶段?会之类的是:

include: common.gitlab-ci.complete.yml
stages:
  - build
  #- unit-test
  #- mutation-test

这些阶段是否会覆盖common.gitlab-ci.complete.yml文件中的一个?

Suppose we have a .gitlab-ci.yml file that reads in a common.gitlab-ci.complete.yml file:

include: common.gitlab-ci.complete.yml

Suppose that common.gitlab-ci.complete.yml has the following stages:

stages:
  - build
  - unit-test
  - mutation-test

In the .gitlab-ci.yml file, how do we ignore the unit-test and mutation-test stages? Would it be something like:

include: common.gitlab-ci.complete.yml
stages:
  - build
  #- unit-test
  #- mutation-test

Would these stages override the one in the common.gitlab-ci.complete.yml file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2025-02-11 08:25:33

(我尚未检查此代码的准确性。将其视为伪代码。)

您要求在舞台上删除所有作业。如果您查看 的文档> include: 关键字,您会注意到YAML始终与您当前的CI脚本合并。因此,不,您不能只添加诸如“在A阶段中禁用所有工作”之类的声明。

这是一个主意...回想一下

如果定义了一个阶段但没有工作使用,则该阶段在管道中不可见...

https://docs.gitlab.com/ee/ee/ee/ee/ci/ci/yaml/ #stages

因此,您可以做的就是添加一种机制,以使该阶段中的所有工作都禁用。然后舞台也将消失。该机制可能正在检查

因此,如果您编写common.gitlab-ci.complete.yml使用模板检查变量以禁用工作...

stages:
  - build
  - unit-test
  - package

.unit-test-stage:
  stage: unit-test
  when: on_success
  rules:
    - if: $DISABLE_UNIT_TESTS
      when: never

unit-test-job-a:
  extends: .unit-test-stage
  script:
    - echo "do stuff"

unit-test-job-b:
  extends: .unit-test-stage
  script:
    - echo "do more stuff"

那么也许您的顶级.gitlab-ci.yml < /code>将简单地在其 global 变量中设置该已知变量类似的部分:

include: common.gitlab-ci.complete.yml

variables:
  DISABLE_UNIT_TESTS: 1

(I have not yet checked this code for accuracy. Treat it as pseudocode.)

You're asking to remove all jobs in a stage. If you look at the documentation for the include: keyword, you'll note that the YAML is always merged with your current CI script. So no, you can't just add a statement like "Disable all jobs in stage A".

Here's an idea... recall that

If a stage is defined but no jobs use it, the stage is not visible in the pipeline...

https://docs.gitlab.com/ee/ci/yaml/#stages

So what you could do is add a mechanism for disabling all jobs in that stage. Then the stage will disappear as well. That mechanism might be checking a variable in rules.

So if you wrote the common.gitlab-ci.complete.yml with templates that check a variable to disable the job...

stages:
  - build
  - unit-test
  - package

.unit-test-stage:
  stage: unit-test
  when: on_success
  rules:
    - if: $DISABLE_UNIT_TESTS
      when: never

unit-test-job-a:
  extends: .unit-test-stage
  script:
    - echo "do stuff"

unit-test-job-b:
  extends: .unit-test-stage
  script:
    - echo "do more stuff"

Then maybe your top-level .gitlab-ci.yml would simply set that known variable in its global variables section like this:

include: common.gitlab-ci.complete.yml

variables:
  DISABLE_UNIT_TESTS: 1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文