Using <<: *defaults syntax in config.yaml, AKA Yaml anchors


#1

Is this syntax valid anymore? I can find NO documentation on it…
I am using it and it works… is this an undocumented feature???

… it’s a way to share configuration across multiple jobs…
is this still valid?
Is this deprecated??
Is there an alternative?

I like to keep the config DRY!

defaults: &defaults
  working_directory: ~/project
  docker:
    - image: python:3.6.1


version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - checkout:
          name: Checkout the source code to build/test

#2

Ah… I get it. This isn’t a CircleCI “capability” – it’s just YAML syntax. Bam.


#3

I also had a HECK of a time finding any documentation on that.
Good luck searching for those special characters!!!

If you want enlightenment, then, what I’m using is called YAML “anchor” format. Here is a doc I found with some information about it:

https://learnxinyminutes.com/docs/yaml/

Here is a snippet from that doc, which creates content that is then shared with other blocks. This is particularly handy when defining multiple jobs in a .circleci/config.yml file that all must use the same container environment.

# Anchors can be used to duplicate/inherit properties
base: &base
    name: Everyone has same name

foo: &foo
    <<: *base
    age: 10

bar: &bar
    <<: *base
    age: 20

#4

I found another good reference to this right in Discuss (wish my search for <<: had found it… )


#5