Variable substitution syntax - unless and like

Hello,
I am attempting to use the variable substitution syntax to iterate through all the steps in a project.
I want to exclude all the steps whose name start with “Set”, e.g. “Set Database”, “Set Web” etc. but pick up all others.
Is there an operator that I could use that would do something like
#{unless !(Octopus.Step.Name like “Set*”}
Do stuff here
#{/unless}

Thanks

Hi,

Thanks for getting in touch! I can tell you that #{unless !(Octopus.Step.Name like "Set*"}Do stuff here #{/unless} is not a valid syntax for variable substitution in Octopus, our unless statement looks something like this: #{unless Octopus.Step.Name condition}run if condition evaluates false#{/unless}

However, To best help you out here, I would need to get some more information regarding what/where exactly your loop is being used for. Is it a run condition variable? Project variable? Is it being run inside a PowerShell script?

There may be a better way of doing this in Octopus but I can not give you much more information without some more context. :slight_smile:

Looking forward to hearing from you and getting this working.

Best regards,
Daniel

Hi,
I am trying to run this inside a send email step.
I want to send an email detailing each step, except the steps that start with with "Set"
It would be inside the each loop of:

    #{each step in Octopus.Step}
    		#{if step.Status.Code!="Abandoned"}
    			#{if step.Status.Code!="Set%"}
	    			<tr style="border:1px solid #000000">
	    				<td><p>#{step | HtmlEscape}</p></td>
	    				<td>
	    					<p
	    						#{if step.Status.Code=="Succeeded"} style="color:Green"#{/if}
	    						#{if step.Status.Code=="Failed"} style="color:Red"#{/if}
	    						#{if step.Status.Code=="Running"} style="color:Blue"#{/if}
	    						#{if step.Status.Code=="Abandoned"} style="color:Orange"#{/if}
	    						#{if step.Status.Code=="Skipped"} style="color:Orange"#{/if}
	    						>
	    					#{step.Status.Code}</p>
	    				</td>
	    			</tr>
	    			#{if step.Status.Error}
	    			<tr>
	    				<td colspan="2">
	    					<p>
	    						<pre>#{step.Status.Error | HtmlEscape}</pre>
	      					<pre>#{step.Status.ErrorDetail | HtmlEscape}</pre>
	      				</p>
	      			</td>
	    			</tr>
    			#{/if}
    			#{/if}
    		#{/if}
    #{/each}

Hi,

Thanks for getting back with that extra info. Unfortunately, our variable substitution syntax is quite limited here. It is only really capable of some basic substitution and logic, it is not able to handle what you are attempting to do.

I had a chat with the developers this morning, it looks like the only option that we could thing of would be for you to create a PowerShell step to build a list of strings that can be output as variables and used in the email step. If you need any further information or help here, please feel free to let me know.

Best regards,
Daniel

Hi Daniel,
Thanks. That would be quite complex, but assuming I had a powershell step that builds a comma separated string with step names like,
Deploy App1, Verify App1, Deploy App2, Verify App2,

How would I modify the above code to fit this in? There doesn’t seem to be an equivalent of the “split” option either

#{each step in Octopus.Actions[ListSteps].Output.StepsVariable}
Do something
#{/each}

Thanks

Hi,

Thanks for getting back. I’m sorry for the delay in getting back to you here. So after some more thoughts, it looks like the best option would be as follows to create a PowerShell step and use PowerShell logic to do the step selection, and create an output variable.

So something like:

script step:

powershell if logic

Set-OctopusVariable -name "EmailVariable" -value "Put Entire email contents in here"

/powershell if logic

email step body:

#{EmailVariable}

After much discussion with the team, it looks like the above will be the only way to make this work. The variable contents can contain quite a bit of data, so putting the entire HTML for the email in there should be fine. :slight_smile:

Let me know how you go with this option or if you run into any issues.

Best regards,
Daniel