Connect-PnPOnline does not work with build agent

Viewed 497

The following powershell snippet from the script works fine in a local machine:

$SharepointConnection = Connect-PnPOnline -Url $ConfigInfo.AProcessDef.ASharePointUrl.ToString().Trim() -Credential $SharepointCredential -ReturnConnection -Verbose -ErrorAction Stop

But it fails while running the very same snippet by a Azure DevOps build agent (self-hosted agent behind a proxy server) on a build VM machine. The build machine is behind a proxy and it is already configured. I already checked with InvokeWebRequest to reach organization's local intranet and internet and it worked fine well. I am getting the following exception with Connect-PnPOnline:

 System.Net.WebException The remote name could not be resolved:

I logged into the vm machine , executed the snippet without any error. I can connect to the domainname.sharepoint.com.

Some hint is appreciated to address this issue.

1 Answers

The issue has been resolved with the following snippet within the powershell script: [system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy($ConfigInfo.Proxy.ToString().Trim()) [system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials [system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true

Related