0

Agent Name: "test agent"
Agent Pool: "Test Pool"
When I am passing these only test and Test is taking. How to make these work with spaces in commant to execute.
-vstsagent is script file variable name (Agentscript.ps1)
parameters('AgentName') is json template parameter.
Please suggest it for total command.

"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Command .\\Agentscript.ps1 -vstsAccount ', parameters('VSTSAccount'),' -vstsAgent ', parameters('AgentName'), '-vstsPoolName ', parameters('AgentPool'))]"

3 Answers3

0

If you want to pass Parameters to the PowerShell Script dynamically, please try below command.

"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -File Agentscript.ps1', ' -vstsAccount ', parameters('VSTSAccount'), ' -vstsAgent ', parameters('AgentName'), ' -vstsPoolName ', parameters('AgentPool'))]"

See this blog and ARM template best practices for details.

Edward Han-MSFT
  • 2,879
  • 1
  • 4
  • 9
  • Not working. When I am using above one getting error like -file. So i removed -Command and executed. Then also it is not taking spaces in Agent pool or vstsPoolName. Ex Pool Name is "Windows Agent Pool". It is taking only Windows as Agent pool name. – Raja Shekar Feb 04 '21 at 16:58
  • Yeah, it supports Windows agents now. – Edward Han-MSFT Feb 05 '21 at 02:06
  • yes it will work. But here the issue is it is not taking spaces in Agent pool name. If I give any pool name with out spaces it works. If existing pool name is have spaces it takes first word only. the deployment get passed. When we check the agent pool no agent is added. But when I checks the VM package downloads > powershel logs there it show only first word of Agent pool is taken. – Raja Shekar Feb 05 '21 at 09:59
0

I find this thread: ARM - How to pass a parameter to commandToExecute with spaces?, maybe you could try below command:

"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File \"Agentscript.ps1', ' -vstsAccount ', parameters('VSTSAccount'), ' -vstsAgent ', '\" \"', parameters('AgentName'), ' -vstsPoolName ', '\" \"', parameters('AgentPool'))]\""
wallezzi
  • 334
  • 1
  • 6
  • **"commandToExecute": "[concat('powershell -ExecutionPolicy Unrestricted -File .\"agentInterService.ps1', ' -vstsAccount ', parameters('VSTSAccount'), ' -PAT ', parameters('PATToken'), ' -vstsAgent ', parameters('AgentName'), ' -vmUserName ', parameters('vmUsername'), ' -vstsPoolName ', '\" \"', parameters('AgentPool'))]\""** Getting error like: \"Command execution finished, but failed because it returned a non-zero exit code of: '1'. The command had an error output of: ''[concat' is not recognized as an internal or external command – Raja Shekar Feb 08 '21 at 17:02
  • if so, it seems that space is not supported. Hope Azure expert can confirm this issue. – wallezzi Feb 09 '21 at 09:41
0
"commandToExecute": "[concat('powershell.exe -ExecutionPolicy Unrestricted -Command .\\agentInterService.ps1  -vstsAccount ', '''' , parameters('VSTSAccount'), '''', ' -PAT ', '''', parameters('PATToken'), '''', ' -vstsAgent ', '''', parameters('AgentName'), '''', ' -Interactive ', '''', parameters('Interactive'), '''',' -AgentNo ', parameters('AgentNo'), ' -vmAdminPassword ', '''', parameters('vmAdminPassword'), '''', ' -vmAdminUserName ', '''', parameters('vmAdminUsername'), '''', ' -vstsPoolName ','''', parameters('AgentPool'), '''')]"

This works if there are any spaces in parameters.