Is it possible to get download URL for the latest successful build and its artifact?
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi @zach-ovic , which way are you wanting to download the artifact? Through the UI, the REST APIs, or via Azure Pipelines?
Hey @elbatk, I would like to add link of the artifact of the latest successful build of some build pipeline to my wiki page. Page is tutorial how to setup some of our company utility software. It would say something like "And download latest build of XYZ" and I would like that XYZ was a link to the artifact. Is something like that possible? Even through REST API.
Ah okay, adding @vijayma to help take a look for you, he would know better than me :)
Great. Thank you.
Sent from my iPhone
On 10 Jan 2019, at 17:47, elbatk notifications@github.com wrote:
Ah okay, adding @vijayma to help take a look for you, he would know better than me :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
I'm also interested on this. How can I create a link to an artifact container folder?
Pinging @vijayma here, I'm not aware that this is possible but it would be nice to put it on Vijay's radar as a potential improvement!
I have tried the REST API to download the artifact but it does not work, https://docs.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get%20artifact?view=azure-devops-rest-5.1
I dont get the downloadUrl in the response as described in the doc.
{"id":4,"name":"nrf-ble-driver-macos","resource":{"type":"PipelineArtifact","data":"850045660D5D5A88FB10CED8AF2428AA84F2F179A5199479037E94E3419B215701","properties":{"RootId":"4E69256EE1933637020D40A90CBC5DE4DB5A7A82947A5AD6CB47818E75C3E5B202"},"url":"https://dev.azure.com/ChunFan/66d06ed9-b064-45b4-9e3e-458cd15cb887/_apis/build/builds/48/artifacts?artifactName=nrf-ble-driver-macos&api-version=5.1-preview.5"}}
re-tagging as doc-bug per this comment:
I dont get the
downloadUrlin the response as described in the doc.{"id":4,"name":"nrf-ble-driver-macos","resource":{"type":"PipelineArtifact","data":"850045660D5D5A88FB10CED8AF2428AA84F2F179A5199479037E94E3419B215701","properties":{"RootId":"4E69256EE1933637020D40A90CBC5DE4DB5A7A82947A5AD6CB47818E75C3E5B202"},"url":"https://dev.azure.com/ChunFan/66d06ed9-b064-45b4-9e3e-458cd15cb887/_apis/build/builds/48/artifacts?artifactName=nrf-ble-driver-macos&api-version=5.1-preview.5"}}
Hey, I'm from one of the pipelines teams that works with build artifacts.
For a while, Pipeline Artifacts weren't populating that downloadUrl field in the Build Artifact, but that should now be fixed as a couple of months ago.
As Josh explained, you can view the artifacts now in the UI (enable multi-stage pipelines preview feature). You can find the URL by opening the browser tools and looking at the network call. It is of the form: https://dev.azure.com/
@vijayma Thank you but this doesn't answer the original question of being able to include a permanent URL that always points to the artifact for the latest build. For example, right now we cannot embed a link on a README that says "here's a link to the latest artifact". The solution you suggested: https://dev.azure.com/esy-ocaml//esy-ocaml/_apis/build/builds/454/artifacts?artifactName=cache-Windows_NT-install-v1&api-version=5.1&$format=zip requires that we still make a rest request to query the latest buildID which rules out being able to embed it on a README for example. Ideally we would have an API like:
https://dev.azure.com/esy-ocaml//esy-ocaml/_apis/build/latest/1/artifacts?branchName=master&artifactName=cache-Windows_NT-install-v1&api-version=5.1&$format=zip but that does not work.
I can't explain it better than jordwalke. A constant URL with the word latest in the query string for example, that one can share as a link is much needed. That's the original question I believe as well and we also need it for out projects. Thank you
I would also like this option for my companies wiki page .. could this please be reopened?
@vijayma @elbatk @joshmgross can someone please recheck this issue? How is it possible its being closed if nothing is solved here? Please read again the issue description.
We need something like "_build/results?buildId=latest&view=artifacts&type=publishedArtifacts"
I think its a relative easy but great improvement that will not break the existing API.
A _simple_ one liner will do.
You can just inline some html in a data url: data:text/html,<a id="btn">download</a><script></script>
And then write some script to talk to the api as discussed. However, this hardcodes a PAT (private access token), so anyone with this link can access any artifacts. Make sure to scope the PAT to artifacts only.
The PAT has to be base64 encoded in a form like this: :[PAT]. example
var o="[organization]/[project]";
var b="[branch]";
var p="[pipeline]";
var a="[artifact]";
var k="[authentication-header]";
var r=new XMLHttpRequest();
r.open("GET","https://dev.azure.com/"+o+"/_apis/build/latest/"+p+"?branchName="+b,false);
r.setRequestHeader("Authorization",k);
r.send(null);
var d=new XMLHttpRequest();
d.open("GET","https://dev.azure.com/"+o+"/_apis/build/builds/"+JSON.parse(r.responseText).id+"/artifacts?artifactName="+a, false);
d.setRequestHeader("Authorization",k);
d.send(null);
document.getElementById("btn").href=JSON.parse(d.responseText).resource.downloadUrl;
Finally remove all the new lines and fit the script into the <script></script> tag to get your download url:
data:text/html,<a id="btn">download</a><script>var o="[organization]/[project]";var b="[branch]";var p="[pipeline]";var a="[artifact]";var k="[authentication-header]";var r=new XMLHttpRequest();r.open("GET","https://dev.azure.com/"+o+"/_apis/build/latest/"+p+"?branchName="+b,false);r.setRequestHeader("Authorization",k);r.send(null);var d=new XMLHttpRequest();d.open("GET","https://dev.azure.com/"+o+"/_apis/build/builds/"+JSON.parse(r.responseText).id+"/artifacts?artifactName="+a, false);d.setRequestHeader("Authorization",k);d.send(null);document.getElementById("btn").href=JSON.parse(d.responseText).resource.downloadUrl;</script>
Hope it helps.
Most helpful comment
I can't explain it better than jordwalke. A constant URL with the word latest in the query string for example, that one can share as a link is much needed. That's the original question I believe as well and we also need it for out projects. Thank you