Created
June 26, 2016 15:44
-
-
Save pietergheysens/954657d2baa08f3c17b958189415b9ab to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 |
Great starter - thanks. :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/.