How do I use a script's output to conditionally run jobs?

I am building a docker container, running tests on the code, pushing the container to Amazon’s ECR, then deploying to Amazon’s EKS. Sometimes we do not want to deploy the container right away. Rather than re-build/test/push a new container that’s identical to the previous one, I’m looking to run a script to check to see if a container exists with my SHA1 and just deploy that.

Workflow with deployment where container doesn’t exist yet:
Script to check if the container exists > build/test > push container to ECR > deploy container to EKS

Workflow with deployment where container does exist:
Script to check if the container exists > deploy container to EKS

Is this at all possible? The script could return a simple true/false or something else, whatever would be more useful. I’ve looked at the documentation as well as a bunch of discussions here, and I haven’t stumbled upon a way to accomplish this. The problem I run into is that conditionals for workflows/jobs are determined before any scripts can run, and there doesn’t seem to be a way around that.

The circleci scripting ‘language’ does not have the features to do this directly. Instead, you would write a shell script to do all the validation. The following link is to ‘run’ command and details how result codes from the script can be handled.

The run command isn’t what I’m having issues with thankfully. The problem I’m having is getting the output of that script ran with the run command to have an impact on which jobs run or not.

There’s no direct method to do this via configuration, but you could go around this by:

  1. write the output of your script to a file
  2. persist it to workspace
  3. attach that workspace to your next job
  4. make a decision based on the file contents in the next job

You can stop the currently running job by using the circleci cli inside your executor (see Configuring CircleCI - CircleCI)

circleci-agent step halt

or if you are running an older executor image

circleci step halt