Skip to content

Instantly share code, notes, and snippets.

@pietergheysens
Created June 26, 2016 15:44
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 pietergheysens/954657d2baa08f3c17b958189415b9ab to your computer and use it in GitHub Desktop.
Save pietergheysens/954657d2baa08f3c17b958189415b9ab to your computer and use it in GitHub Desktop.
Param(
[Parameter(Mandatory=$true)]
[string] $PATPassword
)
$username = "POC-GetBuildDetails"
$basicAuth = ("{0}:{1}" -f $username,$PATPassword)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}" -f $basicAuth)}
$keepforever = @{
keepforever='true'
}
$jsonKeepForever = $keepforever | ConvertTo-Json
#Get Build ID from text file (same folder as powershell script)
$buildID = Get-Content -Path "BuildId.txt"
Write-Verbose "Build ID from Artefact Build ID text file: $buildID" -Verbose
$uriForBuildUpdate = "https://<vstsaccount>.visualstudio.com/DefaultCollection/<TeamProject>/_apis/build/builds/" + $buildID + "?api-version=2.0"
Write-Verbose "Assembling uri for build update: $uriForBuildUpdate" -Verbose
$result = Invoke-RestMethod -Uri $uriForBuildUpdate -headers $headers -Method Patch -Body $jsonKeepForever -ContentType "application/json"
Write-Verbose "Result: $result" -Verbose
Write-Verbose "Build Artifact marked as retain indefintely ..." -Verbose
@pietergheysens
Copy link
Author

The Build ID can now be fetched directly via the build artifact link => use environment variable $env:RELEASE_ARTIFACTS[source-alias][variable-name]. Read more about the artifact variables at https://www.visualstudio.com/en-us/docs/release/author-release-definition/understanding-artifacts. Blogged full context at https://intovsts.net/2016/06/26/retain-vsts-build-indefinitely/.

@JsAndDotNet
Copy link

Great starter - thanks. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment