Don't run scheduled workflow if previous job is still waiting for approval

I have a scheduled workflow that executes and waits for approval. When the next time the workflow is triggered by the schedule, I don’t want it to run. Any ideas on how I can make this happen?

CircleCI does not provide any way to control a ‘state’ flag within just a simple script statement that can be accessed across jobs.

Depending on how long you wish the ‘state’ flag to last you can use a cache as this allows you to store a directory containing a file via a unique key that can be referenced within another job. So the job waiting for approval creates the file and stores it in a known cache location which can be retrieved and checked. Such a solution will cause a job to spin up, but only for a very short time.

Using a git repository would also allow the same type of solution, with the added advantage of more visibility of the information being stored as you could use git to provide an audit trail.

Other options exist, but they involve the use of the API and so need an understanding of calling rest APIs via a command line command like curl - something I have just about got up to speed on, but not to the point that I could talk someone through the process.

I wonder if you couldn’t use their API to query whether there is another job that’s still waiting approval on a given project, such as

(status field of on_hold?) If you query this in your scheduled pipeline, maybe you could implement some logic/conditionals based on the return as to whether or not to put up an approval step.

In other words, the scheduled workflow still runs, but it doesn’t run additional commands if there’s a step awaiting approval in a former scheduled run.

In theory, yes, but it is not a simple task as you have tree walk more than a single result from a single API call - the result would be a clean dedicated application or more shell script than most people would want to code.

The one time I tried to store a value/flag I found it easier to just store it on a key store service that I use - a single curl for each operation (set, read and clear). It should also be possible to use the CircleCI Context API, but that was going to take more R&D and anyway the key store solution allowed me to do other things with the resulting value.

Thanks everyone. The ROI to implement right now isn’t worth the trouble. I figured out a manual workaround by archiving and manually triggering the next step without the hold.