How to download the latest build artifacts from Azure DevOps via REST API without mentioning buildId? - azure

URl mention in documentation:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=4.1
How to get the buildid via REST API or can we download the artifact without buildId

That worked for me, it was on preview back then:
GET https://dev.azure.com/{organization}/{project}/_apis/build/latest/{definition}?branchName={branchName}&api-version=5.0-preview.1

The following API gets a specific artifact for a build:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/artifacts?artifactName={artifactName}&api-version=5.1
You could get a list of builds, including buildid via the following API:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=5.1
With optional parameters:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions={definitions}&queues={queues}&buildNumber={buildNumber}&minTime={minTime}&maxTime={maxTime}&requestedFor={requestedFor}&reasonFilter={reasonFilter}&statusFilter={statusFilter}&resultFilter={resultFilter}&tagFilters={tagFilters}&properties={properties}&$top={$top}&continuationToken={continuationToken}&maxBuildsPerDefinition={maxBuildsPerDefinition}&deletedFilter={deletedFilter}&queryOrder={queryOrder}&branchName={branchName}&buildIds={buildIds}&repositoryId={repositoryId}&repositoryType={repositoryType}&api-version=5.1
While the following API gets the latest build for a definition, optionally scoped to a specific branch:
GET https://dev.azure.com/{organization}/{project}/_apis/build/latest/{definition}?branchName={branchName}&api-version=5.1-preview.1
You could get a list of definitions:
GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions?api-version=5.1
With optional parameters:
GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions?name={name}&repositoryId={repositoryId}&repositoryType={repositoryType}&queryOrder={queryOrder}&$top={$top}&continuationToken={continuationToken}&minMetricsTime={minMetricsTime}&definitionIds={definitionIds}&path={path}&builtAfter={builtAfter}&notBuiltAfter={notBuiltAfter}&includeAllProperties={includeAllProperties}&includeLatestBuilds={includeLatestBuilds}&taskIdFilter={taskIdFilter}&processType={processType}&yamlFilename={yamlFilename}&api-version=5.1

Related

Azure Yaml Pipeline - Update Workitems from multiple Repositories

In a nutshell, I am looking to get a list of work items linked to a git branch.
In more detail
I am working with 4 repositories that I add as resources to my pipeline
- repository: Cms # code repository
name: <ProjectName>/Cms
type: git
ref: develop2022
- repository: QA-Automation # Automated Testing Repo
name: <ProjectName>/QA-Automation
type: git
ref: main
- repository: TdsWDPExplorer # Generate Reports Repo
name: <ProjectName>/TdsWDPExplorer
type: git
ref: master
The Pipeline yaml files them self's are in the 4th Repo and checked out as self
- checkout: Self
path: s/DE-DevOps
I am trying to update the work items associated with the Cms Repository.
I tried using the Workitem Updater task https://marketplace.visualstudio.com/items?itemName=BlueBasher.bluebasher-workitemupdater
But it only sees the workitems associated with the Repository holding the yaml Files (Self).
I also looked at the API to get a list of the work items.
_apis/git/repositories//refs?filter=heads%2fBRANCHNAME&includeLinks=true
Gives me details to a branch but I didn't find the linked work items
Also looking at the workitem I dint see that info
_apis/wit/workitems?ids=ITEM-ID's&$expand=all&api-version=6.0
I am thinking it might be somewhere in _apis/wit/reporting/workitemlinks but haven been able to get the info.
I found a answer that works for me, in a response to Obtain all work items from Azure DevOps that have been merged into a branch via JavaScript
we link the work items to pull requests, I can use the API to query the pull requests in to the given branch and get the linked work items like:
https://dev.azure.com/Organisation/Project/_apis/git/repositories/Cms/pullrequests?searchCriteria.status=completed&searchCriteria.targetRefName=refs/heads/BRANCHNAME&api-version=6.0
I should now be able to extract the ID's and pass them in a PS loop to the Item Updater Task https://marketplace.visualstudio.com/items?itemName=BlueBasher.bluebasher-workitemupdater or using the API to update the workitem
There is also the option to call the API for the pipeline run info https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/get?view=azure-devops-rest-7.1#runresources
But I didn't see a way to extract the work items but the information must be somewhere there as well because I can see the work items listed in the pipeline view by resource

Get all Tests ran in Azure Build Pipeline through REST API

I'm trying to get a list of all tests ran from a Azure Pipeline build through the Azure REST API. I'm trying to use this API call but get an empty list every time:
GET https://dev.azure.com/{organization}/{project}/_apis/test/runs?buildUri={buildUri}&$top={$top}&api-version=6.0
where I'm using the BuildID as the buildUri. Should I be using something else as the buildUri? I only want the top test runs from one build pipeline, not from all pipelines in the project. Even better if I could only get all the tests from one run of the pipeline.
Currently, the only way I've found to solve this is by using the above call to get all runs (none of them have a Build property with data), so I can then use the ids from that call to make the following API call to get which build it is, and filter it manually from there. However, this is way more API calls and data downloaded than I wanted. I want a simple way to get all test runs from a build id.
GET https://dev.azure.com/{organization}/{project}/_apis/test/runs/{runId}?api-version=6.0
I want a simple way to get all test runs from a build id.
As suggested by Xue Meng:
To get the results of each test run:
GET https://vstmr.dev.azure.com/{Orginazation name}/{Project name}/_apis/testresults/resultsbypipeline?pipelineId={buildID}&%24top=20000?api-version=5.2-preview.1
To get the total number of passed tests:
GET https://vstmr.dev.azure.com/{Orginazation name}/{Project name}/_apis/testresults/resultdetailsbybuild?buildId={buildID}&publishContext=CI&groupBy=TestRun&%24filter=Outcome%20eq%20Failed&%24orderby=&shouldIncludeResults=true&queryRunSummaryForInProgress=false?api-version=5.2-preview.1
According to Chubsdad, this seems to be working to get the test result by buildID:
GET https://vstmr.dev.azure.com{org}/{proj}/_apis/testresults/resultdetailsbybuild?buildId={id}&groupBy=TestRun

Azure Artifacts - Download a specific version of maven artifact

We are using azure devops for our CI/CD process. Many a times, in order to do some custom builds, we need to download the specific maven jar from artifact repo.
Is there a way (commandline or API) to do the same ?
Again the question is about download specific jar from azure artifacts.
Azure Artifacts - Download a specific version of maven artifact
The answer is yes. We could use the REST API Maven - Download Package to download the specific jar from azure artifacts:
GET https://pkgs.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/maven/{groupId}/{artifactId}/{version}/{fileName}/content?api-version=5.1-preview.1
First, we need to get the feedId. We could use the REST API Feed Management - Get Feeds to get the feedId:
GET https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/feeds?api-version=5.1-preview.1
Note: The project parameter must be supplied if the feed was created in a project. If the feed is not associated with any project, omit the project parameter from the request.
For other parameters in the URL, we could get it from the overview of the package. Select the package and open the package, we could get following view:
Now, we have all the parameters, feedId, groupId, artifactId, version, fileName.
So, we could use the REST API with -OutFile $(Build.SourcesDirectory)\myFirstApp-1.0-20190818.032400-1.jar to download the package (Inline powershell task):
$url = "https://pkgs.dev.azure.com/<OrganizationName>/_apis/packaging/feeds/83cd6431-16cc-480d-bb4d-a213e17b3a2b/maven/MyGroup/myFirstApp/1.0-SNAPSHOT/myFirstApp-1.0-20190818.032400-1.jar/content?api-version=5.1-preview.1"
$buildPipeline= Invoke-RestMethod -Uri $url -OutFile $(Build.SourcesDirectory)\myFirstApp-1.0-20190818.032400-1.jar -Headers #{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
} -Method Get
Since my maven feed is an organization scoped feed, I omit the project parameter from the URL.
The result:
I've found this way:
Open feed page in Azure, click Connect to feed
Choose Maven, copy the URL from Project setup > repository/url of the pom.xml sample.
That should look like:
https://pkgs.dev.azure.com/YOUR-ORGANIZATION/_packaging/YOUR-FEED-NAME/maven/v1
Append the artifact info to that link:
https://pkgs.dev.azure.com/YOUR-ORGANIZATION/_packaging/YOUR-FEED-NAME/maven/v1/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar
Hint: compare it to the one from maven repository:
https://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar

sass/node-sass issues downloading v4.10.0 from github api

Am trying to use the github api to download the node-sass dependency v4.10.0
Using the github api i am able to get the latest release v4.11.0 by using latest as the release name, however the tag v4.10.0 or any other tag is not working with api calls to single release download. How to fix this.
Below works
https://api.github.com/repos/sass/node-sass/releases/latest
Below doesn't where v4.10.0 is a valid release tag
https://api.github.com/repos/sass/node-sass/releases/v4.10.0
Error
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/releases/#get-a-single-release"
}
I found the answer thought I would post here so it would be useful to others, according to the documentation we can use tags to get individual versions
The below worked for me
https://api.github.com/repos/sass/node-sass/releases/tags/v4.10.0
Use this API and download URL we should be able to fetch all the dependencies if have issues with proxy or access gyp for node sass.

Get latest success commit on GitLab Continuous Integration

I´m working with my own GitLab and GitLab CI server. I´d like to get the latest success commit.
I just can get my latest build status off a branch from the URL:
http://mygitlab.ci/projects/3/status?ref=master
I need that in order to deploy the latest success version of my repo, but I really don´t understand CI with own GitLab and there are not a lot of documentation.
UPDATE:
i.e. In the picture you can see the latest 3 commits and their status. I really need to get the latest success commit (763a3077).
Solved:
Here I have the answer. The URL must be something like this:
http://my.gitlabci/api/v1/commits?project_token=<my-project-token>&project_id=<my-project-id>
GET /commits
Parameters:
project_id (required) - The ID of a project
project_token (requires) - Project token
page (optional)
per_page (optional) - items per request (default is 20)
https://docs.gitlab.com/ee/api/commits.html

Resources