I'm trying to upload from teamcity to artifactory using powershell and nant. I've tried two methods using Invoke-WebRequest
as well as newing up a WebClient
. Webclient.UploadFile fails like this:
Exception calling "UploadFile" with "3" argument(s): "An exception occurred during a WebClient request."
While Invoke-WebRequest
fails like this:
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
If I run either of them manually from that machine, it works. If it start powershell as the teamcity agent service user like this
Start powershell -Credential (Get-Credential)
and then run the code manually, it works. Only when teamcity is actually trying to do the deploy does it fail every time. I've applied the
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
fix, I've applied the
[System.Net.ServicePointManager]::CertificatePolicy = {$true}
fix, and it always works when I run it manually but never works when it runs through teamcity. What is going on?
I ended up using a much larger script from another project that uses WebClient
to attempt a 'checksum deploy' to see if the artifact has changed before attempting the actual deploy using code from this answer.