A hook on the cancellation of a deployment?

Hi Octopus Deploy team!

Getting along great with your architecture. Multiple parallel deployments of a mix of single-tenant and multi-tenant instances of our WCF API with IIS, certificate and load balancer management all out of a single PostDeploy script sitting in our NuGet package. One of our biggest problems is that we keep learning more about what we can do but simply don’t have the time to do it all!

However, I’m a bit concerned about deployment cancellation. Part of our deployment process requires we perform operations with IIS and we discovered through some trials that they are not reliable in parallel. As such, we have a simple file I/O-based locking system that ensures only one deployment can do these operations at a time. It works fine.

The problem is that any of those deployments may be cancelled while they hold this lock and, as far as I know, once that cancel button is clicked, I’ve lost control and any opportunity (in that particular deployment) to clear out this lock.

I stuffed a DeployFailed.ps1 in the NuGet package in the hopes it would get invoked on cancellation, but no luck. I put another step in my process to run on failure of the previous step, but this doesn’t get invoked either. Fair enough, makes sense considering we’re not really dealing with a failure.

I really want to avoid some kind of orphaned-lock-management-process that always runs and keeps tabs. Hardly an elegant solution and really just another thing to monitor.

Any suggestions?

Cheers,

Jay

P.S. I’m on Octopus Deploy 2.6.4.951 until we’ve waded through the red tape (internal) to upgrade (but we could expedite this if a newer version offers a decent option)

Hi Octopus team,

does anyone have any ideas on this? I’m open to just about anything that grants me control on the cancellation of a deployment. Have I missed something obvious?

Cheers,

Jay

Hi Jay,

Thanks for getting in touch and sorry for the delayed reply. I have a few thoughts that might help with this scenario.

Firstly, Tentacle already applies a global lock around jobs - a given Tentacle can only ever be running one script or deploying one package at a single time, unless you override it. That lock is released when a deployment is cancelled, so I think you may just be able to rely on this.

Another approach might be to use a system-wide semaphore - these are automatically released when the process holding them is terminated, so that could work too.

There is, sadly, no way to perform compensating activities (like DeployFailed) when a deployment is cancelled.

Hope this helps,

Paul

Hi Paul,

alas, I don’t think either approach can work for us. We’re deploying multiple single-tenant instances on the same tentacle in parallel (we overrode the mutex restriction).

I think we’ll create an entirely separate utility project and have a scheduled task that “deploys” it regularly via the API. It’ll be hideous and regrettable, but it will serve.

Cheers,

Jay