Is it possible to access the same container in later jobs/steps in a workflow?

In short, I’m running a datadog agent within a workflow, running some tests, then I need to stop the agent.

When I have this defined in a single job, it runs fine, however, this isn’t an option and wish it to be handled on the workflow level as I don’t want it to run in all instances of that job being triggered.

So the basics are:

  • start agent
  • run tests
  • stop agent

Now this has been moved to the workflow level, the stop agent step fails as it knows nothing of the service. How can I get this to try and run across all containers currently running or to find the relevant container running the agent service? Is this possible?

The CircleCI scripting environment does not provide tools to do this, instead, you need to combine

  • The use of the API
    CircleCI API
  • Some form of external storage solution to allow data passing from within the running job(s).

This way

  • you can start the job while passing it a known magic key
  • the job can combine the magic key with the ID environment variables from within the job and place them in the store
  • when you want to stop the job you retrieve the IDs via the magic key from the store and call the API

I’ll be honest all of the above is theory as I’ve never had to combine things in such a way and the API is a little light on examples, which will make the whole thing harder to get working.