Reputation: 4215
This is what the documentation says:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&fileId={fileId}&fileName={fileName}&api-version=6.0
But where do I get the fileId
and the fileName
(I assume fileName means that I also need to know the path)?
(I already know how to download the artifact as a zip but that's not what I want to do)
This is related, but I want to use documented API where I don't have to generate a full scope PAT: In Azure DevOps, is it possible to enumerate children pipeline build artifacts recursively with API?
Thanks
Upvotes: 2
Views: 1580
Reputation: 21
For those who are still looking for a work around:
Step 1:
Use https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get?view=azure-devops-rest-4.1
(Notice the api version!), you will get a response like:
{
"id": 000,
"name": "xxx",
"source": "xxx,
"resource": {
"type": "PipelineArtifact",
"data": "THIS IS A FILEID OF THE STRUCTURE OF THE ARTIFACT",
"properties": {
"RootId": "xxx",
"artifactsize": "xxx"
},
"url": "xxx",
"downloadUrl": "xxx"
}
}
Step 2:
Use https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get-file?view=azure-devops-rest-7.1
to download the manifest of the artifact
The fileID would be "response.resource.data" in Step 1.
the response looks like:
{
"manifestFormat": "1.1.0",
"items": [
{
"path": "/some/path/to/file",
"blob": {
"id": "xxx",
"size": 888
}
}
],
"manifestReferences": []
}
Step 3:
Use https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get-file?view=azure-devops-rest-7.1
to download the real file you want
The fileID would be "items[i].blob.id"
Upvotes: 0
Reputation: 43
I found this post as a workaround for the issue, couldn't find any recent answers
https://developercommunity.visualstudio.com/t/download-single-file-from-artifact-via-api/1093589
Current working workaround (as of date of posting):
1. get artifact using https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
2. Get Resource -> DownloadUrl string
3. Replace entire query from "?format=zip" to "?format=file&subPath={path to the item including the root}"
4. Use URL to download file
Note: To the url i had to add "%2F" before the file name that's how the actual url to the file looks like.
Update:
I asked on the developercommunity and their answer was this:
I have reviewed the ticket you mentioned, and you don’t need to get the fileID, but get the resource.data by using this API :
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get artifact?view=azure-devops-rest-5.1
Then, use this API where resource.data is from the previous call (remove # prefix):
GET https://dev.azure.com/{organization}/{project}/_apis/resources/Containers/{resource.data}?itemPath={path to the item including the root}
A way to verify the URL you are constructing is correct, go to the Artifacts page that is linked off the Build Summary page and you will see the option to copy the download URL for an individual file there. The URL should be the same.
https://developercommunity.visualstudio.com/t/Download-single-file-from-drop-artifacts/10000465
Upvotes: 3