azure-pipelines-agent: Cannot connect VSTS agent from Windows Docker container: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The parameter is incorrect

Agent version and platform

Version of agent: v2.111.1/vsts-agent-win7-x64-2.111.1
OS of the machine running the agent: microsoft/windowsservercore:latest

Docker for Windows version: Client: Version: 1.12.2-cs2-ws-beta API version: 1.25 Go version: go1.7.1 Git commit: 050b611 Built: Tue Oct 11 02:35:40 2016 OS/Arch: windows/amd64

Server: Version: 1.12.2-cs2-ws-beta API version: 1.25 Go version: go1.7.1 Git commit: 050b611 Built: Tue Oct 11 02:35:40 2016 OS/Arch: windows/amd64

Host OS: Windows Server 2016 with Containers (10.0.14393) VM runs in Azure. Also tested on-premises.

VSTS type and version

VisualStudio.com https://alexlexproj.visualstudio.com

What’s not working?

By configuring the VSTS agent using config.cmd script inside a docker container I constantly get the following error message:

>> Connect:

Connecting to server ...
An error occurred while sending the request.

This happens in both cases: when I connect to the running container and execute the script interactively as well as from unattended mode (config.cmd --unattended --url https://alexlexproj.visualstudio.com --agent agent1 --pool Default --auth PAT --token XXXXXXXXXXXXXXXXXXX)

The same command works perfect from the host where the container runs.

Predicting questions about network configuration: the docker host runs in Azure and containers are able to communicate with the Internet. I download agent zip archive directly from https://github.com/Microsoft/vsts-agent/releases/download/v2.111.1/vsts-agent-win7-x64-2.111.1.zip by running Invoke-WebRequest inside the container.

I’ve also tested it from container based on microsoft/windowsservercore with installed Visual Studio 2015 and Build Tools. The result is always the same.

Agent diag log

[2017-01-26 15:25:29Z INFO AgentProcess] Agent is built for Windows - win7-x64.
[2017-01-26 15:25:29Z INFO AgentProcess] RuntimeInformation: Microsoft Windows 10.0.14393 .
[2017-01-26 15:25:29Z INFO AgentProcess] Version: 2.111.1
[2017-01-26 15:25:29Z INFO AgentProcess] Commit: f2b339f02e4065d8500c918d883f50c347b7ba57
[2017-01-26 15:25:29Z INFO AgentProcess] Culture: en-US
[2017-01-26 15:25:29Z INFO AgentProcess] UI Culture: en-US
[2017-01-26 15:25:29Z INFO HostContext] Well known directory 'Bin': 'C:\build\agent\bin'
[2017-01-26 15:25:29Z INFO HostContext] Well known directory 'Root': 'C:\build\agent'
[2017-01-26 15:25:29Z INFO AgentProcess] Validating directory permissions for: 'C:\build\agent'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Generation: '1'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1', value name 'Install': '1'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine', value name 'PowerShellVersion': '2.0'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Unsupported version. Skipping.
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Generation: '3'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3', value name 'Install': '1'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', value name 'PowerShellVersion': '5.1.14393.0'
[2017-01-26 15:25:29Z INFO PowerShellExeUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', value name 'ApplicationBase': 'C:\Windows\System32\WindowsPowerShell\v1.0'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework', value name 'InstallRoot': 'C:\Windows\Microsoft.NET\Framework64\'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'SOFTWARE\Microsoft\NET Framework Setup\NDP' contains sub keys:
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'CDF'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'v3.0'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'v4'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'v4.0'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0', value name 'Version' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0', value name '' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0' contains sub keys:
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'Setup'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup', value name 'Version' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4', value name 'Version' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4', value name '' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4' contains sub keys:
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'Client'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  'Full'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client', value name 'Version': '4.6.01586'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client', value name 'Install': '1'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client', value name 'InstallPath': 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client', value name 'Release': '394802'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Type is System.Int32
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Interpreted version: 4.6.2
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', value name 'Version': '4.6.01586'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', value name 'Install': '1'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', value name 'InstallPath': 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', value name 'Release': '394802'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Type is System.Int32
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Interpreted version: 4.6.2
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0', value name 'Version' is null.
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Key name 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0', value name '': 'deprecated'
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Found 2 versions:
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  4.6.2
[2017-01-26 15:25:29Z INFO NetFrameworkUtil]  4.6.2
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Testing for min NET Framework version: '4.5'
[2017-01-26 15:25:29Z INFO CommandLineParser] Parse
[2017-01-26 15:25:29Z INFO CommandLineParser] Parsing 12 args
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: False
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding Command: configure
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: unattended
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: url
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding flag: unattended
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding option 'url': 'https://alexlexproj.visualstudio.com'
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: agent
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding option 'agent': 'agent1'
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: pool
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding option 'pool': 'Default'
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: auth
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding option 'auth': 'PAT'
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] arg: token
[2017-01-26 15:25:29Z INFO CommandLineParser] parsing argument
[2017-01-26 15:25:29Z INFO CommandLineParser] HasArgs: True
[2017-01-26 15:25:29Z INFO CommandLineParser] Adding option 'token': '********'
[2017-01-26 15:25:29Z INFO AgentProcess] Arguments parsed
[2017-01-26 15:25:29Z INFO ProxyConfiguration] No proxy setting found.
[2017-01-26 15:25:29Z INFO Agent] ExecuteCommand
[2017-01-26 15:25:29Z INFO ConfigurationStore] currentAssemblyLocation: C:\build\agent\bin\Agent.Listener.dll
[2017-01-26 15:25:29Z INFO ConfigurationStore] binPath: C:\build\agent\bin
[2017-01-26 15:25:29Z INFO ConfigurationStore] RootFolder: C:\build\agent
[2017-01-26 15:25:29Z INFO ConfigurationStore] ConfigFilePath: C:\build\agent\.agent
[2017-01-26 15:25:29Z INFO ConfigurationStore] CredFilePath: C:\build\agent\.credentials
[2017-01-26 15:25:29Z INFO ConfigurationStore] ServiceConfigFilePath: C:\build\agent\.service
[2017-01-26 15:25:29Z INFO CommandSettings] Flag 'help': 'False'
[2017-01-26 15:25:29Z INFO CommandSettings] Flag 'version': 'False'
[2017-01-26 15:25:29Z INFO CommandSettings] Flag 'commit': 'False'
[2017-01-26 15:25:29Z INFO CommandSettings] Command 'configure': 'True'
[2017-01-26 15:25:29Z INFO ConfigurationManager] ConfigureAsync
[2017-01-26 15:25:29Z INFO ConfigurationStore] IsConfigured()
[2017-01-26 15:25:29Z INFO ConfigurationStore] IsConfigured: False
[2017-01-26 15:25:29Z INFO ConfigurationManager] Is configured: False
[2017-01-26 15:25:29Z INFO NetFrameworkUtil] Testing for min NET Framework version: '4.6'
[2017-01-26 15:25:29Z INFO CommandSettings] Flag 'machinegroup': 'False'
[2017-01-26 15:25:29Z INFO ExtensionManager] Getting extensions for interface: 'Microsoft.VisualStudio.Services.Agent.Listener.Configuration.IConfigurationProvider'
[2017-01-26 15:25:29Z INFO ExtensionManager] Creating instance: Microsoft.VisualStudio.Services.Agent.Listener.Configuration.BuildReleasesAgentConfigProvider, Agent.Listener
[2017-01-26 15:25:29Z INFO ExtensionManager] Creating instance: Microsoft.VisualStudio.Services.Agent.Listener.Configuration.MachineGroupAgentConfigProvider, Agent.Listener
[2017-01-26 15:25:29Z INFO Terminal] WRITE LINE: 
[2017-01-26 15:25:29Z INFO Terminal] WRITE LINE: >> Connect:
[2017-01-26 15:25:29Z INFO Terminal] WRITE LINE: 
[2017-01-26 15:25:29Z INFO CommandSettings] Arg 'url': 'https://alexlexproj.visualstudio.com'
[2017-01-26 15:25:29Z INFO CommandSettings] Remove url from Arg dictionary.
[2017-01-26 15:25:29Z INFO ConfigurationManager] GetCredentialProvider
[2017-01-26 15:25:29Z INFO CommandSettings] Arg 'auth': 'PAT'
[2017-01-26 15:25:29Z INFO CommandSettings] Remove auth from Arg dictionary.
[2017-01-26 15:25:29Z INFO ConfigurationManager] Creating credential for auth: PAT
[2017-01-26 15:25:29Z INFO CredentialManager] GetCredentialProvider
[2017-01-26 15:25:29Z INFO CredentialManager] Creating type PAT
[2017-01-26 15:25:29Z INFO CredentialManager] Creating credential type: PAT
[2017-01-26 15:25:29Z INFO PersonalAccessToken] EnsureCredential
[2017-01-26 15:25:29Z INFO CommandSettings] Arg 'token': '********'
[2017-01-26 15:25:29Z INFO CommandSettings] Remove token from Arg dictionary.
[2017-01-26 15:25:29Z INFO PersonalAccessToken] GetVssCredentials
[2017-01-26 15:25:29Z INFO PersonalAccessToken] token retrieved: 50 chars
[2017-01-26 15:25:29Z INFO ConfigurationManager] cred retrieved
[2017-01-26 15:25:29Z INFO Terminal] WRITE LINE: Connecting to server ...
[2017-01-26 15:25:30Z INFO CommandSettings] Flag 'unattended': 'True'
[2017-01-26 15:25:30Z ERR  Agent] System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The parameter is incorrect
   at System.Net.Http.WinHttpAuthHelper.SetWinHttpCredential(SafeWinHttpHandle requestHandle, ICredentials credentials, Uri uri, UInt32 authScheme, UInt32 authTarget)
   at System.Net.Http.WinHttpAuthHelper.CheckResponseForAuthentication(WinHttpRequestState state, UInt32& proxyAuthScheme, UInt32& serverAuthScheme)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__101.MoveNext()
   --- End of inner exception stack trace ---
   at Microsoft.VisualStudio.Services.Common.VssHttpRetryMessageHandler.<SendAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__45.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__42`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.VisualStudio.Services.Location.Client.LocationHttpClient.<GetConnectionDataAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.VisualStudio.Services.WebApi.Location.VssServerDataProvider.<ConnectAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.Agent.AgentServer.<ConnectAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.Agent.Listener.Configuration.BuildReleasesAgentConfigProvider.<TestConnectionAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.Agent.Listener.Configuration.ConfigurationManager.<ConfigureAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Services.Agent.Listener.Agent.<ExecuteCommand>d__9.MoveNext()
[2017-01-26 15:25:30Z ERR  Terminal] WRITE ERROR: An error occurred while sending the request.

I will very appreciate any help because I ran out of ideas.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 27 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@judavi thank you so much! That solved my issue! I trusted our root cert, but had to also add intermediate certificate.