如何在作业之间分担任务?

How to share tasks between jobs?

我有一个任务想在多个作业中重复使用,但我不想为每个作业重复任务配置。对我来说最好的方法是什么?

示例:

jobs:
- name: build
  plan:
    - get: git-branch
      trigger: true
    - task: get-build-tag  # <---- duplicate of below
      config: {} # truncated for brevity
    - task: build-image
      file: some-stuff-to-do-with-get-build-tag
- name: test
  plan:
  - get: git-branch
    trigger: true
  - task: get-build-tag # <---- duplicate of above
    config: {} # truncated for brevity
  - task: run-tests
    file: also-to-do-with-get-build-tag

请注意那些已将此问题标记为 的人:Concourse 团队指示我 post 在此处专门针对 Concourse 配置提出此问题。如果配置从 YAML 更改为其他内容,尽管与 YAML 无关,此 post 仍可作为参考。

您正在寻找的是 YAML 锚点。

这是您的管道中的样子:

# This is not part of concourse semantics but we allow
# extra keys to support anchoring
# https://github.com/concourse/concourse/issues/116
additional_tasks: 
- &get-build-tag
  task: get-build-tag
  config: {}

jobs:
- name: build
  plan:
    - get: git-branch
      trigger: true
    - *get-build-tag 
    - task: build-image
      file: some-stuff-to-do-with-get-build-tag
- name: test
  plan:
  - get: git-branch
    trigger: true
  - *get-build-tag
  - task: run-tests
    file: also-to-do-with-get-build-tag

如果您想了解我们如何在我们用于大厅团队测试的管道之一中执行此操作的示例,您可以查看 here