How can steps in YAML config be reused?


Hey guys, just converting to circle 2.0 and the question is …

How can we reuse steps… I have a set of steps that need to happen before each job… (configuring apache, php, installing scripts etc ) … this needs to happen for multiple jobs in each instance…

Do I have to copy all the steps over and over again to each job… it seems very non DRY to me… and a bit of nightmare…


If the section of the YAML tree is exactly the same, then references may be the way to go.


YAML anchors and aliases.


For an example:


My advice above was not correct. You can define a YAML block and then replace selected key values within it on a case-by-case basis. See the entry for YAML at Wikipedia, it is pretty useful.


The main limiting factor with trying to work with sharing steps is as noted above. It only works if the exact set of steps is used. While you can merge what I think of as hashes (key/value pairs in YAML), you cannot merge what I usually think of as arrays (i.e. what’s under the steps keyword).

The solution I’ve ended up with is having references for my steps and adding them one at a time in whatever sequence is needed. For example:

  - &step_attach_workspace
      at: /home/circleci

# partial tree
      - *step_attach_workspace
      - run:
      - *save_results  # would also be defined in aliases


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.