-
Notifications
You must be signed in to change notification settings - Fork 214
/
azure-pipelines.yml
105 lines (105 loc) · 3.81 KB
/
azure-pipelines.yml
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
pr:
autoCancel: 'true'
drafts: 'true'
branches:
include:
- '*'
trigger:
batch: 'true'
branches:
include:
- main
- release/*
parameters:
- name: onebranch
displayName: 'One Branch to use'
type: string
default: 'test'
values:
- 'main'
- 'test'
jobs:
- job: OneBranchTrigger
pool:
vmImage: 'ubuntu-latest'
displayName: Trigger Governed Pipeline
steps:
- task: PowerShell@2
displayName: 'Determine pipeline and parameters'
inputs:
targetType: 'inline'
script: |
$message = '$(Build.SourceVersionMessage)'
if ([string]::IsNullOrWhiteSpace($message)) {
$message = 'No message'
}
$message = $message -replace "[^a-zA-Z0-9\s]", ""
$message = $message.Trim()
$message = $message.substring(0, [System.Math]::Min(100, $message.Length))
$branchName = '$(Build.SourceBranch)'
$branchName = $branchName -replace "refs/heads/", ""
if ('$(Build.Reason)' -eq 'PullRequest')
{
$pipelineDefinition = 'Industrial-IoT-PullRequest'
$templateParameters = "ref: $(Build.SourceBranch), buildInfo: '$message'"
Write-Host "Triggering Pull Request build for $(Build.SourceBranch)..."
}
elseif ('$(Build.SourceBranch)' -like 'refs/heads/release/*')
{
$pipelineDefinition = 'Industrial-IoT-Official'
$templateParameters = "branch: $branchName, buildInfo: '$message'"
Write-Host "Triggering official build for branch $branchName..."
}
else
{
$pipelineDefinition = 'Industrial-IoT-Buddy'
$templateParameters = "branch: $branchName, buildInfo: '$message'"
Write-Host "Triggering buddy build for branch $branchName ..."
}
Write-Host "$(Build.Reason): Trigger $pipelineDefinition with '$templateParameters'..."
Write-Host "##vso[task.setvariable variable=pipelineDefinition]$pipelineDefinition"
Write-Host "##vso[task.setvariable variable=templateParameters]$templateParameters"
- task: TriggerBuild@4
displayName: 'Trigger Build'
inputs:
definitionIsInCurrentTeamProject: true
buildDefinition: $(pipelineDefinition)
queueBuildForUserThatTriggeredBuild: false
ignoreSslCertificateErrors: false
useSameSourceVersion: false
useCustomSourceVersion: false
useSameBranch: false
branchToUse: '${{ parameters.onebranch }}'
storeInEnvironmentVariable: true
authenticationMethod: 'OAuth Token'
password: $(System.AccessToken)
enableBuildInQueueCondition: true
dependentOnSuccessfulBuildCondition: false
dependentOnFailedBuildCondition: false
checkbuildsoncurrentbranch: false
failTaskIfConditionsAreNotFulfilled: false
templateParameters: '$(templateParameters)'
- task: PowerShell@2
displayName: 'Update build number and tags'
inputs:
targetType: 'inline'
script: |
$buildId = $(TriggeredBuildIds)
$buildUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$buildId"
Write-Host "Triggered build $buildUrl ..."
Write-Host "##vso[build.addbuildtag]$(pipelineDefinition) build $buildId"
Write-Host "##vso[task.logissue type=warning]$buildUrl"
Write-Host "##vso[build.updatebuildnumber]$buildId"
- task: WaitForBuildToFinish@3
displayName: 'Wait for build to finish'
inputs:
definitionIsInCurrentTeamProject: true
ignoreSslCertificateErrors: false
waitForQueuedBuildsToFinishRefreshTime: '60'
failTaskIfBuildsNotSuccessful: true
cancelBuildsIfAnyFails: false
treatPartiallySucceededBuildAsSuccessful: false
downloadBuildArtifacts: true
clearVariable: true
authenticationMethod: 'OAuth Token'
password: $(System.AccessToken)