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…
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:
aliases:
- &step_attach_workspace
attach_workspace:
at: /home/circleci
# partial tree
jobs:
build_something:
steps:
- *step_attach_workspace
- run: custom_command.sh
- *save_results # would also be defined in aliases