0

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?

sirdank
  • 3,351
  • 3
  • 25
  • 58
  • What do you see in the artifactory 'request.log' after the failure? – Ariel Mar 28 '18 at 04:14
  • @Ariel When called manually, both `Invoke-WebRequest` and `WebClient` show normal entries in Admin -> System Logs. When called through teamcity, neither of them create any entries. – sirdank Mar 28 '18 at 13:03
  • Do you have any proxy in front of Teamcity? It looks like it's a proxy issue that blocks the request – Ariel Mar 28 '18 at 13:28
  • @Ariel not that I know of. If it were, I would think the call would fail when I ran it manually from the teamcity agent, right? – sirdank Mar 28 '18 at 13:55

1 Answers1

0

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.

sirdank
  • 3,351
  • 3
  • 25
  • 58