I’m forced to use GoCD for deployments and stumble across limitations when using it more often than not.

Last thing that made me quite a headache was automatic locking of pipelines. In general this is a good idea. When the pipeline is triggered it is locked to prevent parallel execution which is a good thing when the pipeline deploys a stack of stuff in some cloud environment and you don’t want races of competing pipeline runs.

However if the pipeline errors prematurely the it stays locked. Until somebody bothers to unlock it in the UI. This is very possible in most cases as the pipelines have several steps that might break. I already included cleanup of debris but haven’t been able to unlock it automatically. That is until I had an idea for which I will most probably go to system engineering hell. But since I found quite a few instances of people asking how it can be done on the Interwebs I thought I share it anyway.

The solution is to issue an API call to the GoCD server as last step in the failure case. Unfortunately this can’t be done directly as the pipeline is still running and therefore unable to unlock itself. The GoCD server will respond with an error stating the pipeline must not have active tasks to be unlocked. The answer is atd. It really shouldn’t be – but it works.

The first line removed any port number from the $GO_SERVER_URL which happens to have a non-default port in my case which is different from the port on the reverse proxy.

The at command schedules the API call after a minute to unlock the pipeline at a time when it is finished and the server allows unlocking again.

Disclaimer: Don’t try this at home. For educational purposes only. ;-)

Leave a Reply

Your email address will not be published. Required fields are marked *