-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAzureDevopsBuildTrigger.ps1
44 lines (37 loc) · 1.41 KB
/
AzureDevopsBuildTrigger.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function QueueAzureDevOpsBuild {
param (
[string]$collectionurl = "",
[string]$base64AuthInfo = "",
[string]$releasedDefinitionId = "123"
)
$json = @"
{
"definition":{
"id": $releasedDefinitionId
}
"@
$uri = $collectionurl + "/build/builds?api-version=5.0"
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$buildId = $result.id
Write-Host "Succeeded queued BuildID:" $buildId
return $result
}
function CheckAzureDevOpsBuild {
param (
[string]$collectionurl = "",
[string]$base64AuthInfo = "",
[string]$buildId = ""
)
$uri = $collectionurl + "/build/builds/"+$buildId+"?api-version=5.0"
$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Write-Host "Status:" $result.status
return $result
}
$azureDevopsProjectUrl = "https://dev.azure.com/"
$azureDevopsBase64AuthInfo = "YWRyaWFuLndhc2lleDdtcGpveDRmbjNtmwaXMyYWNjdXI1bDNpMms1cQ=="
$azureDevopsReleasedDefinitionId = "14"
$build = QueueAzureDevOpsBuild -collectionurl $azureDevopsProjectUrl -base64AuthInfo $azureDevopsBase64AuthInfo -releasedDefinitionId $azureDevopsReleasedDefinitionId
while ($build.status -ne "completed") {
Start-Sleep -s 5
$build = CheckAzureDevOpsBuild -buildId $build.id
}