1

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

Dhruvil Vyas
  • 25
  • 1
  • 11

2 Answers2

1

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

marco.m
  • 4,573
  • 2
  • 26
  • 41
  • I am new to concourse, but as per my knowledge, yml just provides the syntax which is understood by concourse. Here I have questioned that is there any way I can edit my yml in such a way that instead of writing `- get: anyrepo1 - get: anyrepo2` for all my jobs, i can write it just once anywhere, which can be understood by concourse. FYI, no help from links provided. TIA – Dhruvil Vyas Jun 25 '19 at 05:06
0

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`

Dhruvil Vyas
  • 25
  • 1
  • 11