Tenanted deployment via trigger: not parallel?

usability
(B Molsbeck) #1

When a tenanted deployment is triggered, a task is created for each tenant. But when the deployment process consists of multiple steps, the deployment of the tenants is done somewhat in parallel.
For instance, the following could be the execution flow:

  1. Process step 1 for tenant A
  2. Process step 2 for tenant A
  3. Process step 1 for tenant B
  4. Process step 3 for tenant A
  5. Process step 1 for tenant C
  6. Process step 2 for tenant B
    etc.

Is it possible to configure that the deployment of each tenant needs to be fully compete, before the next tenant is handled? So:

  1. Process step 1 for tenant A
  2. Process step 2 for tenant A
  3. Process step 3 for tenant A
  4. Process step 1 for tenant B
  5. Process step 2 for tenant B
  6. Process step 3 for tenant B
  7. Process step 1 for tenant C
  8. Process step 2 for tenant C
  9. Process step 3 for tenant C

A workaround would be to create a separate trigger for each tenant on a specific time, but that is very cumbersome.

PS: I know that when setting the task cap to 1 solves the issue, but this solution does not work when the process uses a chain deployment; this uses a second task.

Kind regards,
Bastiaan Molsbeck.

(Tina) #3

Hi Bastiaan,
Thanks for reaching out.

Unfortunately, as you have discovered, there is not an easy way to accomplish consecutive Tenant deployments.

Take a look at our Project Coordination Code Samples on how to perform various tasks related to project coordination along with the rough untested script below for some ideas on how to accomplish this.

var currentId = Octopus.Parameters[“Octopus.Task.Id”];
var projectName = Octopus.Parameters[“Octopus.Project.Name”];

string GetMinTaskId()
{
return repository.Tasks.GetAllActive()
.Where(t => t.Name == “Deploy”)
// This is a shortcut which works depending on whether your project name is unique.
// The alternative is to fetch all the deployments for these tasks and compare the taskIds
.Where(t => t.Name.Contains(projectName))
.Select(t => t.Id)
// This will usually return the first created unless you cross over from say 999 to 1000.
// The important bit is that it’s consistent
.Min();
}
var minTaskId = GetMinTaskId();
while(minTaskId != currentId)
{
Thread.Sleep(TimeSpan.FromSeconds(5));
minTaskId = GetMinTaskId();
}

You may need to exclude Queued tasks from the active tasks.

I hope this helps. Let me know if you have any further questions or concern.

Tina