microsoft / VSTSAgent.PowerShell

Tools for managing and automating your Azure DevOps Agents.
MIT License
29 stars 23 forks source link

Cannot replace existing agent #21

Closed PavelPikat closed 4 years ago

PavelPikat commented 4 years ago

When applying DSC second time, the resource will throw the following exception:

Install-VSTSAgent : Cannot configure the agent because it is already configured. To reconfigure th
'config.cmd remove' or './config.sh remove' first.
At line:1 char:1
+ Install-VSTSAgent -Name "Routing build 01" -Pool "Routing" -ServerUrl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Install-VSTSAgent

This is because -Replace switch in Install-VSTSAgent does not work. Could uninstalling and then installing the agent be a possible workaround here?

PavelPikat commented 4 years ago

Turns out the issue was in the name of the agent. I have spaces, e.g. "Routing build 01", and when DSC resource lookup the agent by calling Get-VSTSAgent -AgentDirectory "C:\VSTSAgent" -NameFilter "Routing build 01" it can't find it, because the actual name became "Routing" (the string before first space).

Changing the name to a string without spaces solved the issue.