How can I force a deployment to wait until another deployment finishes?

(Bob Walker) #1

Octopus is configured to deploy 5, 10, 15, 40 projects to the same set of deployment targets. When deploying than one project the message Waiting for the script in task [TASK ID] to finish as this script requires that no other Octopus scripts are executing on this target at the same time will appear multiple times.

How can we tell one deployment to wait until another deployment finishes?

(Bob Walker) unlisted #2
(Bob Walker) #3

Before diving into the answer, it is important to understand where that message is coming from. Each time a step is run on a deployment target, the tentacle will create a “Mutex” to prevent others projects from interfering with it. An early use case we saw was updating the IIS metabase during a deployment. Concurrent updates would cause random errors.

It is possible to disable the mutex by following this document. It is not something we recommend. Your success rate will vary. It depends on a host of other factors such as application type and Windows version.

Another option is to coordinate the projects using the deploy a release step. Typically this works best when the projects being deployed are part of the same application suite. If you have 50 disparate applications on the same server the deploy a release step will probably not work.

Another option is to include a step at the start of each project which hits the API to check for active releases to the deployment targets for the deployment target. If an active deployment is found then wait until it is done.

The API endpoint to hit is: https://[YOUR URL]/api/Spaces-1/machines/[Machine Id]/tasks?skip=0&name=Deploy&states=Executing%2CCancelling&spaces=Spaces-1&includeSystem=false. You can pull the list of specific machines using the Octopus.Deployment.Machines variable. The pseudo code would be:

activeDeployments = true

while (activeDeployments)
{
      activeDeployments = false
      foreach(machineId in Octopus.Deployment.Machines)
      {
             activeTasks = https://[YOUR URL]/api/[Octopus.Space.Id]/machines/[Machine Id]/tasks?skip=0&name=Deploy&states=Executing%2CCancelling&spaces=[Octopus.Space.Id]&includeSystem=false

             if (activeTasks.Count > 0)
             {
                      activeDeployments = true
             }
      }

      if (activeDeployments = true)
      {
            Sleep for 5 seconds
      }
}
(Bob Walker) listed #4