Multiple Run Conditions

Hi

Using Octopus Server v2020.4.11

I have got a scenario where I am running three Steps in a deployment.

Step 1
Step 2
Step 3

I only want Step2 to run if Step 1 fails using the variable run condition:

#{if Octopus.Step[Step 1].Status.Code == “Failed”}True#{/if}

I only want Step3 to run if Step 2 succeeds using the variable run condition:

#{if Octopus.Step[Step 2].Status.Code == “Succeeded”}True#{/if}

Now I was hoping that Status.Code in above statement would return “Skipped” as suggested here: https://octopus.com/docs/projects/variables/system-variables#Systemvariables-DeploymentStatusTrackingdeploymentstatus

Unfortnately it doesn’t, it is returning Succeeded - and my step is running when I do not what it to :frowning:

The fourth step is just a powershell script printing out

write-host "$($OctopusParameters["Octopus.Step[Step 2].Status.Code"])"

Have I missed something?

I am going to try and work in “Octopus.Action[Step 2].IsSkipped” into my condition and see if I can get that to work. Following is my log of the above with OctopusPrintEvaluatedVariables and OctopusPrintVariables set.

ServerTasks-24522.log.txt (60.0 KB)

Cheers

John

Hi John,

Thank you for reaching out to us with your query.

It looks like you might be hitting the following known issue:

The issue is public so if you wish you can subscribe to it to be notified when it is fixed. Unfortunately there doesn’t seem to be a reliable workaround available at the moment.

I hope this is helpful. Please let me know if you have any questions.

Best Regards,

Charles

Hi Charles,

Thanks for prompt reply and feedback.

I have managed to work round my issue. Here is some of my findings, for others following in my footsteps…

I looked into using Octopus.Action[Step 2].IsSkipped, however this feature did not work as I had hoped/expected, it did not actually pick up where my step had been skipped in the above example. I did however observe it would pick up where a step had been disabled.

Because my steps were executing powershell scripts I ended up using an output variable.

At the end of Step 2 script I added:

Set-OctopusVariable -name RemoveDRDatabase -value "True" 

Then my run condition variable for Step 3 became:

#{if Octopus.Action[Step 2].Output.RemoveDRDatabase == "True"}#{if Octopus.Step[Step 2].Status.Code == "Succeeded"}True#{/if}#{/if}

I probably didn’t need the nested test on the Status.Code == “Succeeded”… but left it in for good measure.

Cheers

John

Hi John,

The workaround you have suggested is a great option for anyone using PowerShell scripts - thank you for sharing it with us, it’s really appreciated!

I’ve added a reference to this ticket to the GitHub issue and hopefully the incorrect status will be updated soon. In the meantime please let us know if you have any other questions.

Best Regards,

Charles

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.