I have 10 deployment targets and for each I have a scoped variable (Project > Variables > Scoped for a target). It is something like a list of connecting strings.
Now, in my last Email step, I want to figure out which “connection string files” are updated. What is the best/easiest way to do this?
I was thinking to set an output variable per deployment target and gather it in the email step. How would I do this or are there better ways?
I also thought about getting it directly from the Variables but I do not know which deployment targets are deploying right?
My pseudo code thinking:
var result = ""
foreach (key in Octopus.Action[StepA].Output[] ) # so all targets that have put something here
{
var data = key in Octopus.Action[StepA].Output[key]
result += data
}
Thanks for getting in touch! I’ve done a bit of testing here to try to get a good solution, and firstly I’ll admit I’m not super familiar with C#, but I was able to get what I think you’re after with the following PowerShell.
Step1 sets the output variable via Set-OctopusVariable -name "OutputVar" -value "#{Variable}", where #{Variable} is defined in the project, with unique values each scoped to a single machine.
Step2 then grabs all of the relevant output variables set only by the machines the first step was run on.
I hope this helps (and isn’t too much of a pain to translate to C#!). Let me know how you go, and don’t hesitate to reach out if you have any further questions or concerns moving forward.
Thanks for following up! You’re correct, this isn’t valid PowerShell, but we have an open-source component called Octostache that provides this variable substitution functionality, and this extended syntax. You can refer to the source code for this if you’re interested.
And you can refer to the additional extended syntax options in the following doc page.
I hope this helps! Let me know if you have any questions or concerns moving forward.
So do you mean I can put your code snippet into a variable?
Im searching for how to implement step 2. In my case that is the email step but of course I can create a separate gather step (ie PS) and use it in my email template.
Im mostly confused because of the write host statements inside it, but also the variables
Thanks for following up, and firstly I’m sorry about getting sidetracked there and neglecting the fact that this is an email step. Powershell scripts can’t be run in email steps, though you can perform variable substitution in them. So I believe the following should get what you’re after in an email step (keeping step 1 that creates the output variables the same):
You’re quite welcome! Theoretically it would be possible to do this in PowerShell only. I haven’t done it myself, but you could store the results from some PowerShell logic into an output variable, then call that output variable in the email step.
I hope that helps! Let me know if I can try to help with anything else!