-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunBuild.ps1
More file actions
50 lines (41 loc) · 1.45 KB
/
Copy pathRunBuild.ps1
File metadata and controls
50 lines (41 loc) · 1.45 KB
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
param (
[Parameter(Mandatory=$true)] $definitionName,
$sourceBranch,
$repositoryName,
$remoteName = "origin",
[hashtable] $parameters = @{}
)
. $PSScriptRoot/Utils.ps1
. $PSScriptRoot/GitUtils/gitUtils.ps1
. LoadSettings
$repositoryName ??= GetCurrentRepositoryName $remoteName
$repositoryId = & $PSScriptRoot\FindRepository.ps1 $repositoryName
$repositoryIdParam = $repositoryId ? "&repositoryId=$repositoryId&repositoryType=TfsGit" : ""
$sourceBranch ??=
($repositoryName -eq (GetCurrentRepositoryName $remoteName)) ? (GetCurrentBranch) : $null
$buildDefinitionsUrl = "$baseCollectionUrl/_apis/build/definitions" `
+ "?name=$definitionName" + $repositoryIdParam
$buildDefinitions = Invoke-RestMethod -Uri $buildDefinitionsUrl `
-Method 'Get' -Headers @{Authorization = $authorization}
if ($buildDefinitions.count -eq 0) {
Write-Error "Build definition $definitionName is not found"
exit
}
$definitionId = $buildDefinitions.value[0].id
$body = @{
definition = @{ id = $definitionId }
}
If ($sourceBranch) {
$body["sourceBranch"] = $sourceBranch
}
If ($parameters) {
$body["templateParameters"] = $parameters
}
$buildsUrl = "$baseCollectionUrl/_apis/build/builds?api-version=2.0"
$build = Invoke-RestMethod `
-Uri $buildsUrl `
-Method 'Post' `
-body ($body | ConvertTo-Json) `
-Headers @{ Authorization = $authorization; "Content-Type" = "application/json" }
Start-Sleep -Seconds 5
WatchBuildById.ps1 $build.id