是否可以在YAML中实现这种重构

发布于 2025-01-28 03:37:10 字数 1157 浏览 3 评论 0原文

我正在使用Concourse管道进行工作,我需要在YAML中复制大量代码,因此我试图重构它,因此它很容易维护,并且最终不会获得成千上万的重复行/块。

在似乎要解决的方式之后,我已经达到了以下YAML文件,但它并没有满足我的所有需求。

add-rotm-points: &add-rotm-points
  task: add-rotm-points
  config:
    platform: linux
    image_resource:
      type: docker-image
      source:
        repository: ((registre))/polygone/concourse/cf-cli-python3
        tag: 0.0.1
        insecure_registries: [ ((registre)) ]
    run:
      path: source-pipeline/commun/rotm/trigger-rotm.sh
      args: [ "source-pipeline", "source-code-x" ]
    inputs:
      - name: source-pipeline
      - name: source-code-x

jobs:
  - name: test-a
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-a
            trigger: true
      - <<: *add-rotm-points
  - name: test-b
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-b
            trigger: true
      - <<: *add-rotm-points

我的问题是我的两个工作都使用了顶部定义的通用任务。但是在通用任务中,我需要将源代码X更改为我在作业中使用的-a或-b版本。

我找不到在每个工作中重复锚点的情况下找到这个实现这一目标的方法,这似乎是相反的生产力。但是我可能没有充分理解的YAML锚/合并。

I'm working on a concourse pipeline and I need to duplicate a lot of code in my YAML so I'm trying to refactor it so it is easily maintainable and I don't end up with thousands of duplicates lines/blocks.

I have achieve the following yaml file after what seems to be the way to go but it doesn't fullfill all my needs.

add-rotm-points: &add-rotm-points
  task: add-rotm-points
  config:
    platform: linux
    image_resource:
      type: docker-image
      source:
        repository: ((registre))/polygone/concourse/cf-cli-python3
        tag: 0.0.1
        insecure_registries: [ ((registre)) ]
    run:
      path: source-pipeline/commun/rotm/trigger-rotm.sh
      args: [ "source-pipeline", "source-code-x" ]
    inputs:
      - name: source-pipeline
      - name: source-code-x

jobs:
  - name: test-a
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-a
            trigger: true
      - <<: *add-rotm-points
  - name: test-b
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-b
            trigger: true
      - <<: *add-rotm-points

My problem is that both my jobs uses the generic task defined at the top. But in the generic task I need to change source-code-x to the -a or -b version I use in my jobs.

I cannot find a way to achieve this without duplicating my anchor in every jobs and that seems to be counter productive. But i may not have full understood yaml anchors/merges.

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

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

发布评论

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

评论(1

以酷 2025-02-04 03:37:10

您需要做的就是在单个任务上映射输入,例如:

add-rotm-points: &add-rotm-points
  task: add-rotm-points
  config:
    platform: linux
    image_resource:
      type: docker-image
      source:
        repository: ((registre))/polygone/concourse/cf-cli-python3
        tag: 0.0.1
        insecure_registries: [ ((registre)) ]
    run:
      path: source-pipeline/commun/rotm/trigger-rotm.sh
      args: [ "source-pipeline", "source-code-x" ]
    inputs:
      - name: source-pipeline
      - name: source-code-x

jobs:
  - name: test-a
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-a
            trigger: true
      - <<: *add-rotm-points
        input_mapping:
          source-code-x: source-code-a
  - name: test-b
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-b
            trigger: true
      - <<: *add-rotm-points
        input_mapping:
          source-code-x: source-code-b

All you need to do is map inputs on individual tasks, like this:

add-rotm-points: &add-rotm-points
  task: add-rotm-points
  config:
    platform: linux
    image_resource:
      type: docker-image
      source:
        repository: ((registre))/polygone/concourse/cf-cli-python3
        tag: 0.0.1
        insecure_registries: [ ((registre)) ]
    run:
      path: source-pipeline/commun/rotm/trigger-rotm.sh
      args: [ "source-pipeline", "source-code-x" ]
    inputs:
      - name: source-pipeline
      - name: source-code-x

jobs:
  - name: test-a
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-a
            trigger: true
      - <<: *add-rotm-points
        input_mapping:
          source-code-x: source-code-a
  - name: test-b
    plan:
      - in_parallel:
          - get: source-pipeline
          - get: source-code-b
            trigger: true
      - <<: *add-rotm-points
        input_mapping:
          source-code-x: source-code-b
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文