-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
64 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
param( | ||
[int]$buildId = -1 | ||
) | ||
|
||
# get script directory | ||
$scriptsDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition | ||
|
||
$projectPath = Split-Path -Parent $scriptsDirectory | ||
|
||
$organization = "https://dev.azure.com/microsoftgraph" | ||
$project = "Graph Developer Experiences" | ||
$pipelineName = "Snippet Generation DevX" | ||
|
||
if ($buildId -eq -1) { | ||
Write-Warning "selecting the latest scheduled build as buildId is not specified" | ||
$buildId = az pipelines build list --organization $organization --project $project --query "[?definition.name=='$pipelineName' && status=='completed' && reason=='schedule'].id" --output tsv | Select-Object -First 1 | ||
} | ||
|
||
$tempFolder = $env:BASE_DIRECTORY | ||
|
||
$artifactExtractDirectory = Join-Path $tempFolder "artifact-extract-directory" | ||
New-Item -ItemType Directory -Force -Path $artifactExtractDirectory | ||
$stableDownloadUrl = "$organization/$project/_apis/build/builds/$buildId/artifacts?artifactName=Generation%20Test%20Results&api-version=5.0&%24format=zip" | ||
$DownloadFolderName = "SnippetGenerationTestResults" | ||
$downloadZipFullPath = Join-Path $artifactExtractDirectory "$DownloadFolderName.zip" | ||
$downloadExtractDirectory = "$(Build.ArtifactStagingDirectory)/TestResults" | ||
|
||
if ([string]::IsNullOrEmpty($env:AZURE_DEVOPS_EXT_PAT)) | ||
{ | ||
Write-Warning "Fetching request token from logged in az account user" | ||
$token = az account get-access-token --query accessToken --output tsv | ||
$auth_header_value = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", $token) | ||
} | ||
else{ | ||
$PAT_token = $env:AZURE_DEVOPS_EXT_PAT | ||
$base64_PAT_token = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$($PAT_token)")) | ||
$auth_header_value = New-Object System.Net.Http.Headers.AuthenticationHeaderValue("Basic", $base64_PAT_token) | ||
} | ||
|
||
try | ||
{ | ||
Invoke-WebRequest -Uri $stableDownloadUrl -OutFile $downloadZipFullPath -Headers @{Authorization=$auth_header_value} | ||
} | ||
catch | ||
{ | ||
Write-Warning "Failed to download artifact $DownloadFolderName" | ||
exit | ||
} | ||
|
||
Expand-Archive -Path $downloadZipFullPath -DestinationPath $downloadExtractDirectory | ||
|
||
Remove-Item $downloadZipFullPath |