-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines-build-sb2.yml
62 lines (56 loc) · 2.27 KB
/
azure-pipelines-build-sb2.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
# @format
# Sandbox 2 Azure Pipeline -- Validate Production Pull Requests
# @description: Creates release for a branch
# https://aka.ms/yaml
trigger: none
pr: none
parameters:
- name: cancelPriorDeployments
displayName: Cancel prior deployments
type: boolean
default: true
variables:
- group: Base-NS-Deploy-Vars
- group: sb2-deploy-acct
- group: NPM-PKG-Token
- group: project-versions
- name: cancelPriorDeployments
value: '${{ parameters.cancelPriorDeployments }}'
- name: SourcedBranch
value: $(SOURCEBRANCH)
stages:
- stage: CancelPriorDeploymentsStage
displayName: Cancel prior deployments
jobs:
- job: CancelPriorDeploymentsJob
displayName: List builds, cancel prior in progress
pool:
vmImage: 'windows-latest'
steps:
- checkout: none
- task: PowerShell@2
displayName: Powershell AzDO Invoke-RestMethod
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
inputs:
targetType: inline
script: |
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
Write-Host "GET $buildsUrl"
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
ForEach($build in $buildsToStop)
{
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
$body = @{ status = "cancelling" } | ConvertTo-Json
Write-Host "PATCH $urlToCancel"
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
}
condition: eq(variables.cancelPriorDeployments, 'true')
- stage: BuildProject
displayName: Deploy NetSuite
jobs:
- job: BuildRelease
steps:
- template: azure-pipelines-build.yml