Variable scope in Step Run Condion

binh.au's Avatar

binh.au

11 Oct, 2017 10:44 AM

Hi,

I'm running Octopus 3.16.7

I've created a Step1 variable and made reference to it with Step2 "Step Run Condition".
In theory the Step1 Variable should be different for each Machine and Step2 should only run on some Machines.
What I'm seeing is Step1 Variable not being Scoped by Machine level and Step2 will always run because the last machine run in Step1 have set the variable to true.

Is this an issue or just the way Octopus work?

Regards
B.

  1. 1 Posted by binh.au on 13 Oct, 2017 10:19 AM

    binh.au's Avatar

    Hello, anyone looking at this?

  2. Support Staff 2 Posted by Kenneth Bates on 13 Oct, 2017 08:55 PM

    Kenneth Bates's Avatar

    Hi,

    Thanks for getting in touch! I'm sorry you're hitting this behavior and for the delay in getting back to you. This should be theoretically possible, however I'm not positive I fully understand your scenario. If step 2 should only run on some machines, would it be a viable solution for you to scope this step to a role that's assigned only to the machines you want it to be run on?

    Could you provide screenshots of your steps (specifically where you're setting the variable, and step 2's run condition)? I'll be happy to re-assess with some more info. :)

    Best regards,

    Kenny

  3. 3 Posted by binh.au on 16 Oct, 2017 08:00 AM

    binh.au's Avatar

    Hi,

    Please find attached a test project that reconstruct the scenario.

    As you can See STEP01 set the local Variable "SchemeDeploy".
    STEP02 reference it in the "Run condition"
    STEP03 Output the STEP01 local Variable "SchemeDeploy"

    The result I have is that STEP02 will not run because the last server STEP01 ran set the local Variable "SchemeDeploy".to False.
    STEP03 shows that STEP01 local Variable "SchemeDeploy" is different on each server.

  4. 4 Posted by binh.au on 16 Oct, 2017 02:24 PM

    binh.au's Avatar

    btw, The machine deployment is dependent on validation rules (e.g. file that exist or don't exist on server). This is why Role scoping will not work. What I have done is have a step that check the server status and another step to take action based on previous check result.

    I really need an answer soon. I'm suppose to be at the end of project development and if the "Run Condition" in a step does not scope by machine then I will have to go about changing all my Script Templates to Script Modules and placing the validation into the script module.

  5. Support Staff 5 Posted by Tom Peters on 18 Oct, 2017 03:50 AM

    Tom Peters's Avatar

    Hi,

    What you are trying to do is not currently possible with Octopus.

    If you have a look at the documentation on Output variables - Output from multiple machines, you can see the six variables that end up getting created in the example scenario.

    What you really want is to use the variables that are scoped to the machines in order to determine whether steps should run. The problem is that the step run condition is not evaluated for each machine, but is instead evaluated once for the whole step. This means that the variables that are evaluated in the step run condition are not scoped to machines.

    If you are using a run condition for a step, then either the run condition is satisfied and the step runs against every machine, or it is not satisfied and it doesn't run against any of the machines.

    So I would recommend that you don't use step run conditions. Instead, manually check the value of the variable at the beginning of a script step (eg STEP02) and skip the rest of the script if the value of the variable indicates that you don't want to continue. This should just work, because at the point in time when the script gets executed, the variables will be scoped to the specific machine that the script is running on.

    Hope that helps! Let me know if you have any more questions, or need further clarification.
    Tom

  6. 6 Posted by binh.au on 18 Oct, 2017 11:37 AM

    binh.au's Avatar

    There's nothing in the help document saying it will not work at "Run Condition".
    Based on what you say, I can understand why it does not but it would of been nice to get the response sooner.

  7. binh.au closed this discussion on 18 Oct, 2017 11:38 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac