Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access file content within an Azure Dev Ops/VSTS artifact using REST API

I am looking to get the contents of a file I pushed as an artifact to Azure DevOps

I was able to get a json response with a URL to the artifact zip by using this API

https://dev.azure.com/uifabric/cd9e4e13-b8db-429a-9c21-499bf1c98639/_apis/build/builds/8838/artifacts?artifactName=drop&api-version=5.0

However, what I really want is the contents of a file called bundlesizes.json within this zip.

I did come across the Get File API here which mentions an API as follows

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=5.0

I tried replacing it as follows

https://dev.azure.com/uifabric/fabricpublic/_apis/build/builds/8838/artifacts?artifactName=drop&fileId=bundlesizes.json&fileName=bundlesizes.json&api-version=5.0

However, I get this error enter image description here

I think what I am missing is the fileId field, where I am not aware what needs to go in. The documentation says fileId is the The primary key for the file. However, I don't know where I can find it.

like image 511
tubby Avatar asked Oct 16 '22 05:10

tubby


1 Answers

Microsoft doesn't have complete documentation on how to get FileID.

You can take a different approach and download the file using below API. You can get the ContainerID through GET build details.

https://collectionurl/tfs/defaultcollection/_apis/resources/Containers/${containerid}?itempath=drop
like image 149
Fairoz Avatar answered Oct 21 '22 01:10

Fairoz