2
votes

I'm trying to download the TFS build artifact using REST API through a Powershell script. I'm getting a 401 Authorized error. Is there anything I'm missing?

invoke-webrequest -uri "https://collectionurl/tfs/DefaultCollection/_apis/build/builds/33002/artifacts?artifactName=drop&api-version=2.0&%24format=zip" -OutFile "C:\Temp\drop.zip" -UseDefaultCredentials

Tried through the browser as well, keeps giving credential pop-up. I verified my account access, all seems to be perfect.

I'm having on-premise TFS 2018.

2

2 Answers

0
votes

Your API in question looks good, seems it just call the download url of entire drop folder. Just like this ticket: How to get the download url of the artifact in Visual Studio Team Services?

According to your description, even through the browser it still keeps giving credential pop-up.

If so, your issue may related credential cache. Try to clear any TFS credential cache stored in Control Pane--Credential Manager.

Besides, instead of using account/password, you could also try to use PAT. Username should be blank. PAT is the password.

Since you are using PAT with on-premise TFS server, check if you already turned off Basic Authentication.

We recommend you keep IIS Basic Authentication turned off at all times when using Azure DevOps Server. Only if necessary should you enable IIS Basic Authentication. When IIS Basic Authentication is enabled on your windows machine, it prevents you from using personal access tokens (PATs) as an authentication mechanism.

Source link.

About more details for how to use powershell to download build artifacts, you could also take a look at this blog-- Downloading Build Artifacts in TFS Build

0
votes

I took a different approach to download the artifact. However if someone is able to find a fix for the above would be appreciated.

I used below API to download artifacts (found out we could download individual files as well). Was able to retrieve Container ID via GET build details.

https://collectionurl/tfs/defaultcollection/_apis/resources/Containers/${containerid}?itempath=drop