Reputation: 35
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
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
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