-
Notifications
You must be signed in to change notification settings - Fork 2
/
BulkRun.ps1
63 lines (51 loc) · 1.53 KB
/
BulkRun.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$PAT,
[Parameter(Mandatory)]
[string]$File,
[bool]$Simulate = $false,
[string]$Organization = "dimotta",
[string]$Project = "demo"
)
$api_version = "6.0-preview.1"
$token = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT"))
$pipeToRuns = Import-Csv -Path "$file"
foreach ( $item in $pipeToRuns )
{
$sb = [System.Text.StringBuilder]::new()
$item.parameters.Split(";") | ForEach {
$parameter = $_.Split("=")
[void]$sb.AppendFormat( '"{0}": "{1}",', $parameter[0], $parameter[1] )
}
$payload = @"
{
"resources": {
"repositories": {
"self": {
"refName": "$($item.branch)"
}
}
},
"templateParameters": {
$($sb.ToString())
}
}
"@
$uri ="https://dev.azure.com/$Organization/$Project/_apis/pipelines/$($item.definitionid)/runs?api-version=$api_version"
if ($Simulate) {
Write-Host $uri
Write-Host $payload
}
$requestParameters = @{
Uri = $uri
Method = "POST"
ContentType = "application/json"
Headers = @{ Authorization="Basic $token" }
Body = $payload
}
if (-not($Simulate)) {
$response = Invoke-RestMethod @requestParameters
Write-Host "$($item.name) $($response.state) on $($item.branch) -> https://dev.azure.com/$Organization/$Project/_build/results?buildId=$($response.id)"
}
}