Azure-pipelines-agent: Deploying agent as "environment" hangs

Created on 9 Apr 2020  Â·  3Comments  Â·  Source: microsoft/azure-pipelines-agent

Agent Version and Platform

agent v2.165.2
windows 2016 CIS

Azure DevOps Type and Version

dev.azure.com/nn-japan

What's not working?

While trying to add a VM as an environment for release, using the following script fails:

$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive\'azagent')){mkdir $env:SystemDrive\'azagent'}; cd $env:SystemDrive\'azagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWD\agent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.165.2/vsts-agent-win-x64-2.165.2.zip';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.\config.cmd --environment --environmentname "LifeJ API dev" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/nn-japan/' --projectname 'API' --auth PAT --token [REMOVED]; Remove-Item $agentZip;

It hangs waiting for tags, as the logs shows:

[2020-04-09 04:46:06Z INFO Terminal] WRITE: Enter Environment Virtual Machine resource tags? (Y/N) (press enter for N) > 
[2020-04-09 04:46:06Z INFO Terminal] READ LINE

Running the script manually in an admin cmd shell works, but does require to press enter once. My guess is a parameter is missing to make the install works without more input.

stale

Most helpful comment

I also face the same issue.

it resolved by just add --unattended parameter in your existing PS Script you get from the portal

Check below example :
$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive'azagent')){mkdir $env:SystemDrive'azagent'}; cd $env:SystemDrive'azagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWDagent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.165.2/vsts-agent-win-x64-2.165.2.zip';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.config.cmd --unattended --environment --environmentname "LifeJ API dev" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/nn-japan/' --projectname 'API' --auth PAT --token [REMOVED]; Remove-Item $agentZip;

All 3 comments

Ran into a similar problem deploying the agent for deployment groups (and actually for self-hosted build agents as well). The PS script you get from the portal won't run as-is. You either have to run the config command interactively, or add a couple parameters to get it to run silently. This is what I did for the deployment group:

.\config.cmd --deploymentgroup --deploymentgroupname "group name" --deploymentgrouptags 'tag' --adddeploymentgrouptags --agent $env:COMPUTERNAME --WindowsLogonAccount 'NT AUTHORITY\SYSTEM' --runasservice --unattended --work '_work' --url 'https://dev.azure.com/org/' --projectname 'project' --replace --auth PAT --token ******;

I had to add deploymentgrouptags, windowslogonaccount, and unattended to get it to finish. *I added replace as well because I was installing the agent on the same machine multiple times to get these issues worked out.

I also face the same issue.

it resolved by just add --unattended parameter in your existing PS Script you get from the portal

Check below example :
$ErrorActionPreference="Stop";If(-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole( [Security.Principal.WindowsBuiltInRole] “Administrator”)){ throw "Run command in an administrator PowerShell prompt"};If($PSVersionTable.PSVersion -lt (New-Object System.Version("3.0"))){ throw "The minimum version of Windows PowerShell that is required by the script (3.0) does not match the currently running version of Windows PowerShell." };If(-NOT (Test-Path $env:SystemDrive'azagent')){mkdir $env:SystemDrive'azagent'}; cd $env:SystemDrive'azagent'; for($i=1; $i -lt 100; $i++){$destFolder="A"+$i.ToString();if(-NOT (Test-Path ($destFolder))){mkdir $destFolder;cd $destFolder;break;}}; $agentZip="$PWDagent.zip";$DefaultProxy=[System.Net.WebRequest]::DefaultWebProxy;$securityProtocol=@();$securityProtocol+=[Net.ServicePointManager]::SecurityProtocol;$securityProtocol+=[Net.SecurityProtocolType]::Tls12;[Net.ServicePointManager]::SecurityProtocol=$securityProtocol;$WebClient=New-Object Net.WebClient; $Uri='https://vstsagentpackage.azureedge.net/agent/2.165.2/vsts-agent-win-x64-2.165.2.zip';if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){$WebClient.Proxy= New-Object Net.WebProxy($DefaultProxy.GetProxy($Uri).OriginalString, $True);}; $WebClient.DownloadFile($Uri, $agentZip);Add-Type -AssemblyName System.IO.Compression.FileSystem;[System.IO.Compression.ZipFile]::ExtractToDirectory( $agentZip, "$PWD");.config.cmd --unattended --environment --environmentname "LifeJ API dev" --agent $env:COMPUTERNAME --runasservice --work '_work' --url 'https://dev.azure.com/nn-japan/' --projectname 'API' --auth PAT --token [REMOVED]; Remove-Item $agentZip;

This issue has had no activity in 180 days. Please comment if it is not actually stale

Was this page helpful?
0 / 5 - 0 ratings