Deployment steps across different roles

Hi!
I have 4 roles in one deployment process. One of a deployment targets have all of this roles.
For each role i have different variables, scoped to the role. For example,value for variable TaskName is “Task1” for role 1 and “Task2” for role2.

I create deployment step with powershell script inside, for example “Stop-SchedulledTask $TaskName”. I expect from octopus that this script will work for both roles and it will stop Task1 and Task2. But octopus stops only one task and marks deployment as completed.

Hi,

Thanks for reaching out. When Octopus reaches your Powershel script step, It evaluates the value of TaskName to only 1 value (the one that matches the most based on your roles). If it finds 2 exact matches, like in this case “Task1” and “Task2”, It’ll pick the first one in the variableset, but it’ll never pick 2 values (which is what you were expecting).

For this to work you’re gonna have to add 1 step per task, and scope each to a different role:

Step 1 - Scope: Role1 ; Script: "Stop-SchedulledTask $TaskName"
Step 2 - Scope: Role2 ; Script: "Stop-SchedulledTask $TaskName"
Step 3 - Scope: Role3 ; Script: "Stop-SchedulledTask $TaskName"
Step 4 - Scope: Role4 ; Script: “Stop-SchedulledTask $TaskName”

This way, when you deploy to a machine that has Role1 and Role2, only steps 1 and 2 will be executed. During each step, $TaskName will have a different value and your Powershell script will stop the correct task.

Hope that helps!

Dalmiro