MarcE
MarcE

Reputation: 3731

TFS (On prem) release pipeline - Discover and use the name of another machine in a deployment group

I have a web site (site A) deployed on machine A, which depends on a service (service B) deployed onto Machine B.

Machine A and B are in the same deployment group, differentiated by tags (App and Service respectively) and I have 2 deployment phases (one for each tag) pushing the code out to the respective boxes

I need to write a value into the configuration of Site A to tell it the location of Service B.

Is there a way of discovering the name of the machine that Service B was deployed to, to keep my deployment truly dynamic?

Put another way, can I discover the name of a machine with a given deployment tag and use it in a variable?

I've tried running local powershell on the deployment agents to update a variable but that update doesn't seem to make it back to the controlling agent so it can't pass the values across between machines.

My fallback is just to use known server names and write the values into configuration but that feels like a massive hack given how dynamic the rest of the system is.

I'm using TFS 2018 on-prem - the GUI based deployment pipeline (no YAML)

Upvotes: 0

Views: 142

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30343

There are predefined agent variables that allow you to reference the machine name in your pipeline.

1,You can refer to the machine name by wrap the predefined variable in "$()", eg. "$(Agent.MachineName)" or "$(Agent.Name)"

enter image description here

This method will get the Agent Name from the Agent.Name property in the Capabilities of the agent.

enter image description here

2,There is another workaround. You can also add a powershell task to script below script to get the local machine name which hosts the agent and assign it to a variable.

You need to define a variable(eg.MachineName) in the Variables tab of your pipeline

enter image description here

echo "##vso[task.setvariable variable=MachineName]$([System.Net.Dns]::GetHostName())"

enter image description here

The second method will get the Machine name from the on premise Computer's properties.

enter image description here

Upvotes: 1

Related Questions