Can I run a job under another job's steps in CircleCI 2.0?

4.5k Views Asked by At

Is it possible to have another job run in the context of another job? I have some jobs that have some steps in common, and I don't want to repeat these steps in the different jobs.

push-production-image:
docker:
  - image: google/cloud-sdk:latest

working_directory: ~/app

steps:
  - setup-gcp-docker
  - run: docker push [image]
1

There are 1 best solutions below

4
On

No you cannot however YAML itself has a way to solve this problem with what is called YAML Anchors and Aliases.

Here's a blog post I wrote on how to do specifically this: https://circleci.com/blog/circleci-hacks-reuse-yaml-in-your-circleci-config-with-yaml/