Run Condition only when Previous step successful and comparing two variables to check if they match

(pratik.surani) #1


I am trying to implement Run Condition based on below two conditions:

  1. Previous steps were successful
  2. Comparing two variables to check if they are same

I have written below:
#{unless Octopus.Deployment.Error}#{Octopus.Environment.Name != DeploymentName}#{/unless}
But it doesnt work. Please advise.

(Daniel Fischer) #3

Hi @pratik.surani,

Thanks for getting in touch! It looks like you are close to having this work, but there are some things to keep in mind when using run conditions in Octopus.

The outer part of your run condition will work as expected.

#{unless Octopus.Deployment.Error}#{/unless}

This will run the step Unless the deployment has an error. The issue lies with your nested variable.

#{Octopus.Environment.Name != DeploymentName}

This variable will not evaluate to anything. For the condition to work, this variable will need to evaluate to a True or a False value. There is also some bad syntax here. DeploymentName needs to be a string encapsulated with "" quotation marks.

The IF statement here is required as you are using the Variable Substitution Syntax, as outlined in the following documentation page.

So if you made the nested variable an IF statement, and provided the expected value if it evaluates, then this will work as expected.

#{unless Octopus.Deployment.Error}#{if Octopus.Environment.Name != "DeploymentName"}True#{/if}#{/unless}

With the above example condition, the step will only run if the deployment has no errors, and IF the environment you are deploying to is NOT equal to the string DeploymentName.

I have tested this on my VM and it works as I would expect.

Does this help you?

Let me know if you have any further questions here or run into any issues.

Best regards,