Skip to content

Commit d63af58

Browse files
committed
👷 more azure support for prod & PRs
1 parent c28951e commit d63af58

6 files changed

Lines changed: 223 additions & 83 deletions

.ci/workflows/azure-pipelines-build-deploy.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# @format
2+
3+
# https://aka.ms/yaml
4+
5+
trigger: none
6+
7+
pr: none
8+
9+
parameters:
10+
- name: cancelPriorDeployments
11+
displayName: Cancel prior deployments
12+
type: boolean
13+
default: true
14+
15+
variables:
16+
- group: Base-NS-Deploy-Vars
17+
- group: prod-deploy-acct
18+
- group: NPM-PKG-Token
19+
- name: cancelPriorDeployments
20+
value: '${{ parameters.cancelPriorDeployments }}'
21+
- name: TestList
22+
value: '[Modules-Query]=Modules/Query,[Modules-Record]=Modules/Record,[Modules-Task]=Modules/Task,[Modules-Utility]=Modules/Utility,[Modules-Validate]=Modules/Validate'
23+
- name: SourcedBranch
24+
value: $(SOURCEBRANCH)
25+
26+
stages:
27+
- stage: CancelPriorDeploymentsStage
28+
displayName: Cancel prior deployments
29+
jobs:
30+
- job: CancelPriorDeploymentsJob
31+
displayName: List builds, cancel prior in progress
32+
pool:
33+
vmImage: 'windows-latest'
34+
steps:
35+
- checkout: none
36+
- task: PowerShell@2
37+
displayName: Powershell AzDO Invoke-RestMethod
38+
env:
39+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
40+
inputs:
41+
targetType: inline
42+
script: |
43+
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
44+
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
45+
Write-Host "GET $buildsUrl"
46+
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
47+
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
48+
ForEach($build in $buildsToStop)
49+
{
50+
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
51+
$body = @{ status = "cancelling" } | ConvertTo-Json
52+
Write-Host "PATCH $urlToCancel"
53+
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
54+
}
55+
condition: eq(variables.cancelPriorDeployments, 'true')
56+
- stage: BuildProject
57+
displayName: Deploy Branch
58+
jobs:
59+
- job: BuildRelease
60+
steps:
61+
- template: azure-pipelines-build.yml
62+
- stage: SetBuildTagStage
63+
displayName: Add Build Tags
64+
jobs:
65+
- job: SetBuildTagJob
66+
displayName: Add Build Tag via PR Tag
67+
pool:
68+
vmImage: 'windows-latest'
69+
steps:
70+
- checkout: none
71+
- task: PowerShell@2
72+
displayName: 'Add Build Tag'
73+
condition: succeeded() # Only when all previous tasks have succeeded
74+
env:
75+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
76+
inputs:
77+
targetType: inline
78+
script: |
79+
Write-Host "##vso[build.addbuildtag]$env:buildLabel"
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# @format
2+
# https://aka.ms/yaml
3+
4+
trigger: none
5+
6+
pr: none
7+
8+
parameters:
9+
- name: cancelPriorDeployments
10+
displayName: Cancel prior deployments
11+
type: boolean
12+
default: true
13+
14+
variables:
15+
- group: Base-NS-Deploy-Vars
16+
- group: sb-deploy-acct
17+
- group: NPM-PKG-Token
18+
- name: cancelPriorDeployments
19+
value: '${{ parameters.cancelPriorDeployments }}'
20+
- name: TestList
21+
value: '[Modules-Query]=Modules/Query,[Modules-Record]=Modules/Record,[Modules-Task]=Modules/Task,[Modules-Utility]=Modules/Utility,[Modules-Validate]=Modules/Validate'
22+
- name: SourcedBranch
23+
value: $(SOURCEBRANCH)
24+
25+
stages:
26+
- stage: CancelPriorDeploymentsStage
27+
displayName: Cancel prior deployments
28+
jobs:
29+
- job: CancelPriorDeploymentsJob
30+
displayName: List builds, cancel prior in progress
31+
pool:
32+
vmImage: 'windows-latest'
33+
steps:
34+
- checkout: none
35+
- task: PowerShell@2
36+
displayName: Powershell AzDO Invoke-RestMethod
37+
env:
38+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
39+
inputs:
40+
targetType: inline
41+
script: |
42+
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
43+
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
44+
Write-Host "GET $buildsUrl"
45+
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
46+
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
47+
ForEach($build in $buildsToStop)
48+
{
49+
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
50+
$body = @{ status = "cancelling" } | ConvertTo-Json
51+
Write-Host "PATCH $urlToCancel"
52+
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
53+
}
54+
condition: eq(variables.cancelPriorDeployments, 'true')
55+
- stage: BuildProject
56+
displayName: Deploy Update
57+
jobs:
58+
- job: BuildRelease
59+
steps:
60+
- template: azure-pipelines-build.yml
61+
- stage: SetBuildTagStage
62+
displayName: Add Build Tags
63+
jobs:
64+
- job: SetBuildTagJob
65+
displayName: Add Build Tag via PR Tag
66+
pool:
67+
vmImage: 'windows-latest'
68+
steps:
69+
- checkout: none
70+
- task: PowerShell@2
71+
displayName: 'Add Build Tag'
72+
condition: succeeded() # Only when all previous tasks have succeeded
73+
env:
74+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
75+
inputs:
76+
targetType: inline
77+
script: |
78+
Write-Host "##vso[build.addbuildtag]$env:buildLabel"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# @format
2+
3+
steps:
4+
- template: azure-pipelines-select-branch.yml
5+
- task: JavaToolInstaller@0
6+
inputs:
7+
versionSpec: '17'
8+
jdkArchitectureOption: 'x64'
9+
jdkSourceOption: 'PreInstalled'
10+
- checkout: self
11+
clean: true
12+
persistCredentials: true
13+
- script: |
14+
# Fetch origin branches
15+
git fetch --all --prune
16+
17+
## leave detached head mode
18+
git checkout $(SourcedBranch)
19+
20+
# Install NetSuite SDF
21+
npm i
22+
npm run setup-server --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET
23+
24+
## Uncomment if not using Azure DevOps Releases to deploy changes to NetSuite
25+
# npm run deploy-pipeline --verbose
26+
27+
## Run Jest tests
28+
npm run test
29+
env:
30+
# NPM Token variable if using private NPM repository for packages
31+
# NPM_TOKEN: $(NPM_TOKEN) #uncomment to use
32+
# NetSuite Secret Token within Azure Library/Variables
33+
ENV_TOKENSECRET: $(TOKENSECRET)
34+
# NetSuite Secret Token ID within Azure Library/Variables
35+
ENV_TOKENID:
36+
$(TOKENID)
37+
38+
# Publish test results to Azure
39+
# - task: PublishTestResults@2
40+
# inputs:
41+
# testResultsFormat: 'JUnit'
42+
# testResultsFiles: '**/test-report*.xml'
43+
# failTaskOnFailedTests: true
44+
# testRunTitle: 'NetSuite Module Deployment Tests'
45+
46+
## Publish artifact to Azure for use in Release pipeline
47+
# Alternative would be to deploy in RunNPMScripts step
48+
# - task: CopyFiles@2
49+
# inputs:
50+
# contents: |
51+
# **
52+
# !**/node_modules/**
53+
# !**/.vscode/**
54+
# !**/docs/**
55+
# !**/resources/**
56+
# !**/__tests__/**
57+
# targetFolder: $(Build.ArtifactStagingDirectory)
58+
# - task: PublishBuildArtifacts@1
59+
# inputs:
60+
# pathToPublish: $(Build.ArtifactStagingDirectory)
61+
# artifactName: Build-$(buildLabel)

.ci/workflows/azure-pipelines-docs.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ trigger:
1919
# exclude:
2020
# - production
2121

22-
pr: none
23-
2422
pool:
2523
vmImage: ubuntu-latest
2624

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# @format
2+
3+
steps:
4+
- script: TRIMMED_NAME=$(echo "$(System.PullRequest.SourceBranch)" | sed "s:refs/heads/::") && echo "##vso[task.setvariable variable=SourceBranch;]$TRIMMED_NAME"
5+
condition: ne(variables['System.PullRequest.SourceBranch'], '')

0 commit comments

Comments
 (0)