List Of Machines In Environment Being Deployed

I do have script which needs to run and set variables for each machine in Environment being deployed during release. “Octopus.Deployment.Machines” gives me machine names for Octopus Server but I need list of machines within environment being selected. Is there any way to grab this information in script please?

Hi David,

Thanks for getting in touch!

We have the below script that uses the Octopus.Client to retrieve the list of machines included within a deployment. As written it outputs the names of these machines but you can amend it as required.

I hope this helps, please let me know if you have any further questions.

Regards,
Paul

Thank you Paul for such a quick response ! Appreciate that. I tried but I ended up getting blank string while my deployment has 3 machines. No errors either. I suspect it could be API key but how do i confirm what is the problem area here? Any logs generated where I can have a look please.

Edit:

Further digging into issue I found that $OctopusParameters[‘Octopus.Deployment.Machines’] will give me empty string. In my case I am trying to access list of machines involved as part of deployment environment selected and in our case it has 3 servers still it shows empty string.

I think I found work around.

  1. Make call to [“api/environments/all”]
  2. Runtime find selected deployment environment.
  3. Compare name from #2 with list obtained in step # 1 and grab environment id.
  4. Use environment id obtained from # 3 and make call to “api/environments/[Environment Id]/machines” and get list of machines.

I hope this might help someone as well.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.