I have a pipeline where machines can be assigned dynamically, so each time I have new machine I need to got and add variable which is scoped to the new machine and it is reused within other steps where machine name is needed.
Example:
HostName
= MachineOne, scope to MachineOne
= MachineTwo, scope to MachineTwo.local.net
I would prefere to use Octopus variable Octopus.Machine.Hostname
instead, but as you can see from the scope hostname (or even Octopus.Machine.Name) are not suitable as machines are registered with 3 part name.
Is it possible to have a PowerShell script to parse Octopus.Machine.Hostname to get the first part of the name to pass it to variable HostName? Or is there another way?
Greetings radamonas! What about using an Output variable? You could have a PowerShell script execute at the beginning of the deployment which could do the parsing as you suggested, then assign that to an output variable. The HostName variable could then be assigned the value of the output variable and should have the name you are looking for in it. Out of curiosity, what implications are there if you use the 3 part name?
Hope this helps!
Regarding implications:
A) HostName is used for setting up SQL replication, this was failing due to 3 part server names;
B) Not dev environments have 1 part host names, so this would be like a significant deviation from upper envs.
I will try with the suggestion you came.
Thanks.
Hi, I was able to get results based on your suggestion, however I wondering is this right name for the variable to assign to variable HostName #{Octopus.Action[StepName].Output.VarName}?
As it doesn’'t seem very flexible once the step name is changed there will be a need to review variable as well. Or am I missing sothing here?
Yes, you are using the correct variable, that is how the feature was designed.