Download Azure DevOps Pipeline Artifact with Powershell

Date posted: Post reading time: 1 minute or less

How to programmatically download the latest successful version of an artifact from an Azure DevOps Pipeline using Powershell.

$ORGANIZATION  = "..."
$PROJECT       = "..."
$PIPELINE_NAME = "..."
$ARTIFACT_NAME = "..."

$PIPELINE_ID = (az pipelines show `
	--organization $ORGANIZATION `
	--project $PROJECT `
	--name $PIPELINE_NAME `
	--only-show-errors `
	| ConvertFrom-Json).id
	
$RUN_ID = (az pipelines runs list `
	--organization $ORGANIZATION `
	--project $PROJECT `
	--pipeline-ids $PIPELINE_ID `
	--status completed `
	--top 1 `
	--only-show-errors `
	| ConvertFrom-Json).id

az pipelines runs artifact download `
	--artifact-name $ARTIFACT_NAME `
	--path . `
	--run-id $RUN_ID `
	--only-show-errors