Dhruvil Vyas
Dhruvil Vyas

Reputation: 35

How to give same 'get' to multiple jobs in concourse

Instead of giving the same '- get' to multiple jobs, is there any way that I can optimize my code by giving common '- get', if it is allowed in any way.

Currently, I have given the same code (- get) for different jobs

jobs:
- name: Name1
  plan:
  - aggregate:
    - get: anyrepo1
    - get: anyrepo2
  - task: taskhere
    image: anyimage1
    file: file1.yml
- name: Name2
  plan:
  - aggregate:
    - get: anyrepo1
    - get: anyrepo2
  - task: taskhere
    image: anyimage1
    file: file2.yml

I am not getting any error, but want to optimize the code

Upvotes: 1

Views: 1384

Answers (2)

Dhruvil Vyas
Dhruvil Vyas

Reputation: 35

You can use below code to reuse the same thing again and again. In my case i am using a variable "jobs_get_common".

`jobs_get_common: &jobs_get_common - get: repo1 - get: repo2

jobs: - name: Converge-BHS plan: - aggregate: *jobs_get_common - task: anytask image: image1 file: task.yml`

Upvotes: 0

marco.m
marco.m

Reputation: 4859

Ah, it seems that the "optimization" you are looking for is at the YAML level. You want to reduce YAML duplication. This is independent from Concourse, this technique can be applied to any YAML file.

You can use YAML merge keys and anchors.

See

Upvotes: 1

Related Questions