4

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]
halfer
  • 19,824
  • 17
  • 99
  • 186
Seyi Adekoya
  • 443
  • 5
  • 11

1 Answers1

5

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/

FelicianoTech
  • 3,894
  • 2
  • 13
  • 18
  • My only problem is the steps that are run usually lose context outside the anchor e.g. if i install a binary in the anchor, I don't have access to the binary outside the anchor and alias – Seyi Adekoya Aug 09 '18 at 06:08
  • You can 1) Do the installation in the anchor, 2) Install the binary in a Docker image, or 3) Persist the binary in workspaces. – FelicianoTech Aug 13 '18 at 02:05
  • @ FelicianoTech please how do I persist an installed and already configured gcloud sdk? – Seyi Adekoya Aug 13 '18 at 07:53
  • You can use Workspaces to persist the binary and any config files where gcloud stores data: https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs – FelicianoTech Aug 14 '18 at 15:15