Now when we use the code below to fetch all JOB-SERVER-MACHINES names, we either get exact #{Octopus.Machines[machine].Name} placeholder or blank value after Octopus Deploy variable substitutions:
#{each machine in Octopus.Environment.MachinesInRole[JOB-SERVER-MACHINES]}#{Octopus.Machines[machine].Name}#{/each}
Here’s the Octopus Deploy Versions…
Octopus Deploy Server version: Octopus 3.3.4
Octopus Deploy Tentacle version: Octopus 3.3.4
PowerShell version: 4.0
.NET Framework version: 4.5
OS version: Windows Server 2012 R2
Anything that is causing this to not function properly?
Thanks for reaching out. This isn’t particularly easy, but there’s ways around it. Before I come up with an approach I need to know: Are you trying to use the machine name in an email step, or are you trying to loop over the machine names to do something fancier from a Powershell step?
The approach to take will vary a lot depending on what you are trying to do, so please try to explain this as much as you can
We are using this in an Octopus Deploy Variable, and we are using this to loop over the machine names so that it can dynamically get the machine name without touching the octopus deploy variables frequently, and by “tagging” the machines via Environments (using roles) without the need to create an Octopus Deploy Release to get the latest snapshot of Octopus Deploy Variables’ values. We also utilized the server roles as an environment identifier too, to test and use the said code, especially in traversing the machines in specific roles.
Let’s say the variable name holding the code is JobMachineServer. We are expecting the code #{each machine in Octopus.Environment.MachinesInRole[JOB-SERVER-MACHINES]}#{Octopus.Machines[machine].Name}#{/each} to get the machine names MACHINE1-QA and MACHINE1-UAT respectively, but we only get empty value and/or #{Octopus.Machines[machine].Name} value, and not the machine names.
Given the setup above, if we deploy to QA environment and we added 3 more machines (let’s say MACHINE3-QA, MACHINE4-QA), if my assumption is correct, all machines, MACHINE1-QA, MACHINE2-QA, MACHINE3-QA and MACHINE4-QA should have the JobMachineServer variable value MACHINE1-QA.
Let me know if you need more clarifications with the scenarios.
We would really appreciate an update on this because we are on a time deadline to get quite a few clients setup.
To clarify, we are attempting to use the foreach snippet within a Library variable set value that is being used to populate an entry in a configuration file. We would like it to dynamically populate the server name based on the role assigned to the server. We have only 1 machine in that role per environment. We expect that it would fill in the machine name, but currently we get a blank value or the unresolved snippet.
ex. value = http://#{each machine in Octopus.Environment.MachinesInRole[JOB-SERVER-MACHINES]}#{Octopus.Machines[machine].Name}#{/each}/