Problem statement: I want to fetch the latest artifact bar url from azure artifactory, to deploy it to the openshift container platform. I am using this ({organization_url}/{project_name}/_apis/build/builds?api-version=7.1-preview.7) to fetch the buildid and through buildid I am able to fetch the bar url from Azure artifacts, but here the problem is ({organization_url}/{project_name}/_apis/build/builds?api-version=7.1-preview.7) this api wont fetch the buildid which ran 2 months ago. When the pipeline rans after the two months, it will ignore the bar url and it wont get deployed.
Now I need help to get the latest bar url directly without using build id, example if my appplicationname and artifact name is ace.bar, using this bar name it should get the latest version of the bar. and construct the barurl.
7
this api is giving count 1000
This REST API has a limit of 1000 builds. To get the URL of your target artifact, you can add a definitions
filter in the request to list builds only of your target pipeline.
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions={definitions}&api-version=7.1-preview.7
definitions: A comma-delimited list of definition IDs. If specified, filters to builds for these definitions.
- You can get the definition ID of your target pipeline from the UI. Go to your target pipeline, you can see the definition id as shown below. For this example, the request is
https://dev.azure.com/{organization}/{project}/_apis/build/builds?definitions=411&api-version=7.1-preview.7
- You can also get the definition id from REST API Pipelines – List.
For my suggestion “use DownloadBuildArtifacts@1 task to download the latest artifact” mentioned in the comment above, this task will not return the URL of the artifact directly, it will download your target artifact into the working directory of your deployment pipeline. Then you can deploy it directly to your platform. Therefore, you don’t need to download artifacts using the REST API.
YAML:
- task: DownloadBuildArtifacts@1
inputs:
buildType: 'specific'
project: '{the project holding your target pipeline}'
pipeline: '{your target pipeline}'
buildVersionToDownload: 'latest'
downloadType: 'single'
downloadPath: '$(System.ArtifactsDirectory)'
Classic:
6