Unauthenticated API for download of an azure pipeline artifact - azure-devops

The azure pipelines web interface provides a link to download pipeline artifacts on public pipelines regardless of whether your session is authenticated or not. However, the api for getting a download link does not work in this case. HOWEVER however, the download link produced by that API does work if you copy it into an unauthenticated session. How can I obtain a download URL for a public pipeline artifact without authenticating and without scraping the public web interface?
My use case is providing a tool to manually debug CI runs that work locally but fail in CI by replicating the CI environment in a docker container and downloading the exact build used in the failing CI run (a pipeline artifact). The interface I would like to provide for this is a command that takes as an argument a URL of a Github pull request, parses the relevant pipeline parameters out of it, and launches the docker container with the URL of the artifact to download. This should work, and it has worked in the past by scraping the artifact download URL out of the public azure web interface, but this breaks frequently.

Related

Azure build pipelines - need to know the complete path where the build logs are stored on the Microsoft Hosted Agent

I have a build pipeline and I need to download the logs generated from the build pipeline and save to some location in my repo. I need to know where these logs are stored on a Microsoft hosted agent from where I can copy to a path in my repos. Also, I don't want to use the below REST API to get the build logs -
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/logs?api-version=5.1

How can I access the artefact from a pull request for which a build was run?

I'm using azure for a windows app and so I don't really need to go as far as CD as that isn't really relevant. We eventually plan to move to the cloud but for now that is not the case.
I have now got my .net (c#) build running as a build pipeline and I have a develop branch which Pull Requests are used to merge in changes. What I want is for a tester to be able to pick up the build artefact that was created for a particular bug or product backlog item when the pull request was successfully completed. Is this possible without having a Release Pipeline? I don't currently have a subscription that would allow me to create a release pipeline.
How can I access the artefact from a pull request for which a build was run?
Indeed, just as Lucas said, if we are starting from the pull request to solve this problem, it is really difficult. But we could try reverse thinking to start with the build pipeline.
Azure devops provided us some predefined variables, like Build.BuildId, System.PullRequest.PullRequestId.
So, we could use the REST API Pull Requests - Update in the build pipeline to update the comment with the link to the artifact.
PATCH https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=5.1
Since the current build is triggered by a pull request, we could use the predefined variable System.PullRequest.PullRequestId to get the pullRequestId directly.
Now, we just need to get the link of the artifact, we could use the Artifacts - Get to get the artifact info:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=4.1
We could get the buildId by the predefined variable Build.BuildId, then we will get the download URL:
So the idea of summing up my solution is to use REST API Pull Requests - Update in the build pipeline to update the comment of the pull request, which contains the download path of the artifact.
Note: You could also add custom conditions in the REST API task in the build pipeline:
and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
So, with this setting, only the build triggered by the pull request will execute this rest api task.
Hope this helps.
The pull request build that you defined can publish artifacts, see this documentation to see how to do it.
Once those artifacts are published, your tested can browse/download them on the build run page (click on header pa> "Related" > click on "#number of artifacts you publish# published").
Alternatively, you could add a task to copy your artifacts to an Azure Blob Storage, but that would require more configuration.
One can find build id with branchName filter :
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.0&reasonFilter=pullRequest&definitions={buildDefinitionId}&branchName=refs/pull/{pullRequestId}/merge
Once builder id has been retrieved, get artifact by name :
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=6.0

Publishing artifacts to an external server

We are using azure devops pipeline to build our application including a Azure build agent. At the end of this process, I would like to publish the artifacts to an on-premise server shared directory (which will connect to company mandated deployment process (repliweb)).
Is that possible?
Looking at the documentation it looks like I can use publish artifact or copy file step (or maybe even ftp).
Our IT organization needs to know the IP/port so that the firewall rules can be authored.
Where can I get that information?
I suppose the other possibility would be have our server pull the artifact from Azure devops.
Publishing artifacts to an external server
For this issue, you can try to use FTP Upload task in the pipeline. Using this task in a build or release pipeline to upload files to a remote machine using the File Transfer Protocol (FTP), or securely with FTPS.
For details,please refer to this document.

Service web hook - get artifacts of succeeded build?

We're using Azure Pipelines to build our project. We configured a Service Hook for the Event "Build completed" and everything is working as planned.
However, we don't receive information about the build's artifacts. How to obtain a specific artifact from the build in the web hook?
Unfortunately the information about the build artifacts not passed in the Build Completed JSON.
What you can do it's after you catch the event make a Rest API call in your service to get the artifacts details according the build id (build id you of course got in the service hook json).
The Rest API to get artifacts details is Artifacts - List.

Unity Cloud Build link with Continuous Integration systems

After a successful build in Unity Cloud Build I would like to send the generated .zip file url to a Continuous Integration system like Travis CI in order to to deploy that file into another server. To do this right now I need to call a custom webhook in my own server that checks (via API) the last build link and starts a Travis CI build via HTTP POST method.
What's the best approach to do this without needing my intermediate step? I'have tried to do this HTTP POST request inside the post-script method in Unity Cloud Build but this seems to be a bad workaround.