0

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.

Just a student
  • 10,560
  • 2
  • 41
  • 69
neezer
  • 19,720
  • 33
  • 121
  • 220
  • @Anthon See my edit above. – neezer Jun 30 '17 at 08:03
  • 6
    Whether someone instructed you to post this question or not has **nothing** to with this being able to be a duplicate or not. I am not sure why you made that edit, all that stuff after "note to" has nothing to do with your problem nor with programming. As such that edit is inappropriate, distracts from your question and degrades it. Even assuming this question gets closed as duplicate it doesn't go away, so people can still find it if they look for [tag:concourse]. It is not necessary to have a separate *answer* about anchors for every program that happens to use YAML for their config. – Anthon Jun 30 '17 at 08:28
  • 4
    [This post is being discussed on meta](https://meta.stackoverflow.com/q/351505/5244995). – Jed Fox Jun 30 '17 at 11:50

1 Answers1

4

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.

Just a student
  • 10,560
  • 2
  • 41
  • 69