Implement azure artifact downloader
This commit is contained in:
commit
a9e7737024
5 changed files with 101 additions and 0 deletions
44
main.ps1
Normal file
44
main.ps1
Normal file
|
@ -0,0 +1,44 @@
|
|||
. './listBuilds.ps1'
|
||||
. './listArtifacts.ps1'
|
||||
|
||||
$token = 'token'
|
||||
$instance = 'dev.azure.com/myorganization'
|
||||
$project = 'myproject'
|
||||
$branches = 'V1.0.0.0', 'V1.0.0.1'
|
||||
$outDir = "$PSScriptRoot\output"
|
||||
|
||||
|
||||
|
||||
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
|
||||
$headers.Add("Authorization", "Basic ${token}")
|
||||
|
||||
# Remove outDir
|
||||
if (Test-Path $outDir) {
|
||||
Remove-Item -Recurse $outDir
|
||||
}
|
||||
|
||||
# Get the list of builds in a repo
|
||||
$builds = ListBuilds -token $token -instance $instance -project $project
|
||||
|
||||
ForEach ($branch in $branches) {
|
||||
# Select only the last build for the branches you want
|
||||
$lastBuild = $builds.value | Where-Object { $_.sourceBranch -eq "refs/heads/$branch"} | Select-Object -First 1
|
||||
|
||||
# Get the list of artifacts for each build
|
||||
$listArtifacts = ListArtifacts -token $token -instance $instance -project $project -buildId $lastBuild.id
|
||||
$artifacts = $listArtifacts.value
|
||||
|
||||
# Create output directory
|
||||
$outputDir = "$outDir\$branch"
|
||||
New-Item -Path $outDir -Name $branch -ItemType Directory
|
||||
|
||||
# Download the artifacts
|
||||
ForEach ($artifact in $artifacts) {
|
||||
$artifactName = $artifact.name
|
||||
$outputFile = "$outputDir\$artifactName.zip"
|
||||
Invoke-RestMethod -Uri $artifact.resource.downloadUrl -Method 'GET' -Headers $headers -OutFile $outputFile
|
||||
|
||||
# Unzip
|
||||
Expand-Archive $outputFile -DestinationPath $outputDir
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue