Stop Octopus Deploy queuing deployments triggered by a scheduled trigger if deployment already running

We have a project that runs every few minutes using a scheduled trigger (it cannot be a runbook for several reasons). Sometimes, the deployment takes longer than five minutes to run and when that happens, another deploy is scheduled before the first one is finished, which means that the process is running unnecessarily.

Is there any way to tell the trigger mechanism or the deploy mechanism to not queue a deploy if one is already running?

Scheduled deployment triggers in Octopus ( solely queue a deployment, they do not perform any checks, so, as you are probably encountering if the project is already running, a deployment task will be queued.

One way to avoid this is to have two projects. Let’s call the project that does the actual (potentially long-running) work, that you want to run on a schedule ChildProject and the second ParentProject.

The ParentProject will have a script step which checks to see if the ChildProject is currently running for the current Environment, if it is not, it creates a deployment for ChildProject for the current Environment. Because the ParentProject will take seconds to complete, we avoid project deployments queuing up.

Let’s say ChildProject runs a Powershell Sleep for 3 minutes, and there is a scheduled deployment trigger for ParentProject that triggers a deployment every 2 minutes. In this example it will be quite common that ChildProject will not be deployed.

In the image above, we can see that ParentProject ran on the schedule and that on the 2:20 PM deployment it found the ChildProject was already executing, so did not create a new deployment for it.

A script to use in the script step of the ParentProject can be found here:

You can parameterize the environment and project to deploy.