I have a task that I want to re-use in multiple jobs, but I don't want to have to repeat the task configuration for every job. What's the best way for me to do that?
Example:
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
Note to those who have flagged this question as a duplicate: I was instructed by the Concourse team to post this question on here specifically about Concourse configuration. Should configuration ever change from YAML to something else, this post could still act as a reference despite having nothing to do with YAML.
What you're looking for are YAML anchors.
Here's what that would look like in your pipeline:
# 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
If you want an example of how we do that in one of the pipelines we use for our testing on the concourse team, you can check it out here.