Skip to content

Instantly share code, notes, and snippets.

@MaxMelcher
Created January 12, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaxMelcher/18ef8e3cfa3113e497360ad20eefd137 to your computer and use it in GitHub Desktop.
Save MaxMelcher/18ef8e3cfa3113e497360ad20eefd137 to your computer and use it in GitHub Desktop.
#use this task to execute inline powershell in your build https://marketplace.visualstudio.com/items?itemName=petergroenewegen.PeterGroenewegen-Xpirit-Vsts-Build-InlinePowershell
#add the script below
#pass the following as arguments: -buildnumber $(Build.BuildNumber) -out $(Build.ArtifactStagingDirectory)\out.txt -guid $(System.TeamProjectId)
#replace the two placeholders with a Personal Access Token and your VS Account name; the part behind https://dev.azure.com/
Param(
[string]$buildnumber,
[string]$out,
[string]$guid
)
$token = "<PAT TOKEN>"
$vsAccount = "<VS ACCOUNT NAME>"
Write-Output "BuildNumber $buildnumber"
Write-Output "Out $out"
Add-Type -AssemblyName System.Web
$user = ""
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uri = "https://dev.azure.com/$vsAccount/$guid/_apis/build/builds/$buildnumber/logs/8"
$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
write-output $result
$result | out-file $out
write-output "##vso[task.uploadfile]$out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment