Last active
March 6, 2020 14:28
-
-
Save davidroberts63/ef6693d0776b7896d023b842a4a39347 to your computer and use it in GitHub Desktop.
AzPi-Build-Canceler
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( | |
[String] | |
$ProjectName, | |
[String] | |
$AccountName, | |
[PSCredential] | |
$TokenCredential | |
) | |
Import-Module VSTeam -Version 6.4.4 | |
Set-VSTeamAccount -Account $AccountName -SecurePersonalAccessToken $TokenCredential.GetNetworkCredential().Password | |
$project = Get-VSTeamProject -Name $ProjectName | |
$buildsToCancel = (Get-VSTeamBuild -ProjectName $project.Name -StatusFilter notStarted) + | |
(Get-VSTeamBuild -ProjectName $project.Name -StatusFilter InProgress) + | |
(Get-VSTeamBuild -ProjectName $project.Name -StatusFilter Postponed) | |
$buildsToCancel | ForEach-Object { | |
Invoke-VSTeamRequest -Url ($_._links.self.href + '?api-version=6.0-preview.5') -method patch -body '{"status":4}' -ContentType 'application/json' -verbose | |
# Last minute change: if the above doesn't work, use the below line. | |
#Invoke-VSTeamRequest -ProjectName $_.projectName -area 'build' -resource 'Builds' -id $_.Id -method patch -body '{"status":4}' -verbose -version '6.0-preview.5' -ContentType 'application/json' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment