Azure Pipelines agent proxy settings not working as expected

痴心易碎 提交于 2021-02-10 05:19:11

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/55942362/azure-pipelines-agent-proxy-settings-not-working-as-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!