# How to use YAML Templates in buildkite?

**URL:** <https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065>\
**Category:** General\
**Created:** [May 30, 2022, 6:03am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065 "2022-05-30T06:03:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 30, 2022, 6:03am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/1 "2022-05-30T06:03:34Z")

</div>

I’ve been looking at the docs but I couldn’t find it.

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 30, 2022, 7:28am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/2 "2022-05-30T07:28:40Z")

</div>

Hey @Joe good question.

This page here discusses pipeline steps and yaml with a few examples: [Defining your pipeline steps | Buildkite Documentation](https://buildkite.com/docs/pipelines/defining-steps)

Hope that helps. Let us know if you need more info

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [May 30, 2022, 8:00am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/3 "2022-05-30T08:00:15Z")

</div>

Will step default also work with plugins

```auto
agents:
  queue: "something"
plugins:
  - plugin1:
       config-1:
  - plugin2:
       config-2:

steps:
  - command: "blah.sh"
  - command: "blahblah.sh"
  - label: "Yada"
    command: "yada.sh"
    agents:
      queue: "other"
    plugins:
     - plugin1:
          config-1: "other"

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [May 30, 2022, 8:12am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/4 "2022-05-30T08:12:37Z")

</div>

Ohh another good question!

You can’t define a default plugin list like this. But you can make use of YAML anchors to define such a plugin once and reference it where ever it is needed. Take a look at [YAML anchors | Bitbucket Cloud | Atlassian Support](https://support.atlassian.com/bitbucket-cloud/docs/yaml-anchors/) to see how to use them

---

<div class="post-metadata">

**Author:** ![Joe](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/joe/32/1080_2.png) [@Joe](https://forum.buildkite.community/u/Joe)\
**Post date:** [June 8, 2022, 6:29am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/5 "2022-06-08T06:29:09Z")

</div>

Hi, jarryd

Does the plugins step syntax work with objects? yaml anchors do not work with arrays.

Below will turn the plugins into object type

```auto
definitions:
    plugins: &allplugins
      - plugin1: &plugin1
           config-1:
      - plugin2: 
           config-2:

steps:
  - label: "Yada"
    command: "yada.sh"
    plugins: 
        <<: *allplugins
        plugin1: 
            <<: *plugin1
            config-2:

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [June 9, 2022, 3:01am UTC](https://forum.buildkite.community/t/how-to-use-yaml-templates-in-buildkite/2065/6 "2022-06-09T03:01:08Z")

</div>

My use of anchors ends with the `<<:` operator to extend/override things so I’m not too sure.  
I found this that might help though [assets - Is there a way to alias/anchor an array in YAML? - Stack Overflow](https://stackoverflow.com/questions/4948933/is-there-a-way-to-alias-anchor-an-array-in-yaml) which has a different way of putting the anchors on the list items.

I’m not sure if it does deep merging either but you could test it out. Something like this (not tested)

```yaml
definitions:
    plugins: &allplugins
      - plugin1: &plugin1
           config-1:
      - plugin2: 
           config-2:

steps:
  - label: "Yada"
    command: "yada.sh"
    <<: *allplugins
    plugins: 
        plugin1: 
            <<: *plugin1
            config-2:

```
