简体   繁体   中英

Azure Pipelines agent proxy settings not working as expected

When configuring a local build agent on a Windows 2016 server, I use the following proxy config settings:

.\config.cmd --proxyurl http://192.3.4.5:8080 --sslskipcertvalidation

This allows the build server to connect to Azure DevOps behind the proxy without issues, however the powershell build is having trouble connecting out to the internet. I solved this by setting an environmental variable at the beginning of the build command as such:

$env:http_proxy = "192.3.4.5:8080"

The final issue is a step in the build requires to winrm to a VM hosted directly on the build server and it cannot connect. I've tried configuring the agent's .proxybypass file as such:

localhost
192\.3\.4\.*

This has failed to solve the issue however. Any ideas on how to set the proxy bypass in the build step? Is there another powershell env variable I could set?

The proxy settings ensure the agent can call out. The tasks rely on a lot of different technologies and each use different proxy configurations, IP masks and whitelists. As such, if your agent is behind a proxy, you may need to configure a lot of different proxy settings on said machine. It's a pain. Even for task authors, like me, who can't just take the agent config and copy it one-to-one to the technology each task relies on.

Powershell relies on the Windows internet settings proxy configuration for the user running the task. You can also override the .NET proxy configuration Powershell relies on the .NET proxy settings, how to change those on the fly is listed here: https://stackoverflow.com/a/209072/736079

Use the .NET class in the powershell build:

[net.webrequest]::defaultwebproxy = new-object net.webproxy "http://$env:proxy_ip" 

and then add

[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM