Skip to content

Commit 9bdb1a2

Browse files
committed
🔧 Update Azure Pipeline Configurations Across Multiple Environments
- Modified `.ci/workflows/azure-pipelines-build-prod.yml` to refine deployment and remove unused variables. - Updated `.ci/workflows/azure-pipelines-build-sb.yml` with clearer display names and streamlined tasks. - Added new pipeline file `.ci/workflows/azure-pipelines-build-sb2.yml` for Sandbox 2 environment. - Refined `.ci/workflows/azure-pipelines-build.yml` for better readability and efficiency. - Overhauled `.ci/workflows/azure-pipelines-docs.yml` for enhanced documentation generation and deployment. - Adjusted `.ci/workflows/azure-pipelines-select-branch.yml` to better handle source branch variables. - Created `.ci/workflows/azure-pipelines-validate-prod-pr.yml` for stringent validation of production pull requests.
1 parent 3c3d35f commit 9bdb1a2

7 files changed

Lines changed: 327 additions & 91 deletions

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# @format
22

3+
# NetSuite Azure Pipeline -- Validate Production Pull Requests
4+
# @description: Creates release for a branch
35
# https://aka.ms/yaml
46

57
trigger: none
@@ -15,11 +17,11 @@ parameters:
1517
variables:
1618
- group: Base-NS-Deploy-Vars
1719
- group: prod-deploy-acct
20+
- group: sb-deploy-acct
1821
- group: NPM-PKG-Token
22+
- group: project-versions
1923
- name: cancelPriorDeployments
2024
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'
2325
- name: SourcedBranch
2426
value: $(SOURCEBRANCH)
2527

@@ -54,26 +56,8 @@ stages:
5456
}
5557
condition: eq(variables.cancelPriorDeployments, 'true')
5658
- stage: BuildProject
57-
displayName: Deploy Branch
59+
displayName: Deploy NetSuite
5860
jobs:
5961
- job: BuildRelease
6062
steps:
6163
- 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"

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# @format
2+
3+
# Sandbox 1 Azure Pipeline -- Validate Production Pull Requests
4+
# @description: Creates release for a branch
25
# https://aka.ms/yaml
36

47
trigger: none
@@ -15,10 +18,9 @@ variables:
1518
- group: Base-NS-Deploy-Vars
1619
- group: sb-deploy-acct
1720
- group: NPM-PKG-Token
21+
- group: project-versions
1822
- name: cancelPriorDeployments
1923
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'
2224
- name: SourcedBranch
2325
value: $(SOURCEBRANCH)
2426

@@ -53,26 +55,8 @@ stages:
5355
}
5456
condition: eq(variables.cancelPriorDeployments, 'true')
5557
- stage: BuildProject
56-
displayName: Deploy Update
58+
displayName: Deploy NetSuite
5759
jobs:
5860
- job: BuildRelease
5961
steps:
6062
- 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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# @format
2+
3+
# Sandbox 2 Azure Pipeline -- Validate Production Pull Requests
4+
# @description: Creates release for a branch
5+
# https://aka.ms/yaml
6+
7+
trigger: none
8+
9+
pr: none
10+
11+
parameters:
12+
- name: cancelPriorDeployments
13+
displayName: Cancel prior deployments
14+
type: boolean
15+
default: true
16+
17+
variables:
18+
- group: Base-NS-Deploy-Vars
19+
- group: sb2-deploy-acct
20+
- group: NPM-PKG-Token
21+
- group: project-versions
22+
- name: cancelPriorDeployments
23+
value: '${{ parameters.cancelPriorDeployments }}'
24+
- name: SourcedBranch
25+
value: $(SOURCEBRANCH)
26+
27+
stages:
28+
- stage: CancelPriorDeploymentsStage
29+
displayName: Cancel prior deployments
30+
jobs:
31+
- job: CancelPriorDeploymentsJob
32+
displayName: List builds, cancel prior in progress
33+
pool:
34+
vmImage: 'windows-latest'
35+
steps:
36+
- checkout: none
37+
- task: PowerShell@2
38+
displayName: Powershell AzDO Invoke-RestMethod
39+
env:
40+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
41+
inputs:
42+
targetType: inline
43+
script: |
44+
$header = @{ Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN" }
45+
$buildsUrl = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds?api-version=$(devOpsApiVersion)"
46+
Write-Host "GET $buildsUrl"
47+
$builds = Invoke-RestMethod -Uri $buildsUrl -Method Get -Header $header
48+
$buildsToStop = $builds.value.Where({ ($_.status -eq 'inProgress') -and ($_.definition.name -eq "$(Build.DefinitionName)") -and ($_.id -lt $(Build.BuildId)) })
49+
ForEach($build in $buildsToStop)
50+
{
51+
$urlToCancel = "$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_apis/build/builds/$($build.id)?api-version=$(devOpsApiVersion)"
52+
$body = @{ status = "cancelling" } | ConvertTo-Json
53+
Write-Host "PATCH $urlToCancel"
54+
Invoke-RestMethod -Uri $urlToCancel -Method Patch -Header $header -ContentType application/json -Body $body
55+
}
56+
condition: eq(variables.cancelPriorDeployments, 'true')
57+
- stage: BuildProject
58+
displayName: Deploy NetSuite
59+
jobs:
60+
- job: BuildRelease
61+
steps:
62+
- template: azure-pipelines-build.yml

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

Lines changed: 154 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,175 @@ steps:
77
versionSpec: '17'
88
jdkArchitectureOption: 'x64'
99
jdkSourceOption: 'PreInstalled'
10+
displayName: Install JDK17
1011
- checkout: self
1112
clean: true
1213
persistCredentials: true
14+
displayName: Checkout Repository
1315
- script: |
16+
## Validate Repo is Current
1417
# Fetch origin branches
18+
git fetch --all
19+
## leave detached head mode
20+
git checkout origin/$(HEADBRANCH)
21+
git reset --hard origin/$(HEADBRANCH)
22+
echo "##vso[task.setvariable variable=sfdxExitCode;]0"
23+
npm i
24+
npm run setup-server-token --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET --releaserun=$(RELEASE_RUN) --flatobjects=NO --validaterun=YES
25+
### Adding git credentials
26+
git config user.email "YOUR@EMAIL_HERE.com"
27+
git config user.name "Azure Pipeline"
28+
## Committing all changes temporarily, these won't be pushed
29+
git add -A && git commit -m "🔮 Clearing Changes for Validation Testing"
30+
npm run validate-repo-current
31+
displayName: Validate Repo Current
32+
env:
33+
ENV_TOKENSECRET: $(TOKENSECRET)
34+
ENV_TOKENID: $(TOKENID)
35+
NPM_TOKEN: $(NPM_TOKEN)
36+
failOnStandardError: false
37+
continueOnError: false
38+
39+
- task: PowerShell@2
40+
inputs:
41+
targetType: 'inline'
42+
script: |
43+
$exitCode = $(sfdxExitCode)
44+
$forceRelease = "$(FORCERELEASE)"
45+
if ($exitCode -ne 0) {
46+
Write-Host "Force Release: $forceRelease"
47+
if ($forceRelease -ne "YES" ) {
48+
Write-Error "Failing task since return code was {0} while expected 0."
49+
Write-Host "##vso[task.logissue type=error]Changes Detected...STOPPING RELEASE!"
50+
exit($exitCode)
51+
} else {
52+
Write-Host "##vso[task.logissue type=warning;code=100;]Changes Detected...continuing -- Forced Release"
53+
}
54+
} else {
55+
Write-Host "No Changes Detected...continuing"
56+
}
57+
failOnStderr: false
58+
displayName: Validate Repo is Clean
59+
60+
- script: |
61+
## Reset RELEASE_BUILD variable in case this is just docs or CI changes
62+
echo "##vso[task.setvariable variable=RELEASE_BUILD]false"
63+
64+
65+
## Fetch origin branches
1566
git fetch --all --prune
67+
## leave detached head mode
68+
git checkout $(SourcedBranch) --force
69+
git reset --hard origin/$(SourcedBranch)
70+
displayName: Initialize Repository
71+
env:
72+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
73+
- script: |
74+
OBJECTS_BUILD_PATH=$(BUILD_DIR)/$(OBJECTS_PATH)
75+
## Cleanup build dir if exists
76+
rm -rf $(BUILD_DIR)
77+
mkdir $(BUILD_DIR)
78+
## Copy files to build directory
79+
find . ! -path "*$(BUILD_DIR)*" | cpio -pdm ./$(BUILD_DIR)
80+
## Clean out objects directory
81+
rm -rf $OBJECTS_BUILD_PATH
82+
mkdir $OBJECTS_BUILD_PATH
83+
## Copy object definitions to build dir without subpath tree
84+
displayName: Initialize Build Directory
85+
86+
- task: Bash@3
87+
inputs:
88+
filePath: './.ci/scripts/flattenObjectPaths.sh'
89+
arguments: '$(BUILD_DIR)/$(OBJECTS_PATH) $(HEADBRANCH) $(SourcedBranch)'
90+
failOnStandardError: true
91+
displayName: Flatten Object Trees
1692

93+
- script: |
94+
## Switch to build directory to continue deployment
95+
cd $(BUILD_DIR)
96+
# Fetch origin branches
97+
git fetch --all --prune
1798
## leave detached head mode
1899
git checkout $(SourcedBranch)
19-
20-
# Install NetSuite SDF
21100
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
101+
npm run setup-server --sourcebranch=$(SourcedBranch) --headbranch=$(HEADBRANCH) --account=$(ACCOUNT) --authid=$(AUTHID) --tokenid=$ENV_TOKENID --tokensecret=$ENV_TOKENSECRET --releaserun=$(RELEASE_RUN) --flatobjects=YES --validaterun=NO
102+
### Commenting out because this is moving to release workflow
25103
# npm run deploy-pipeline --verbose
26-
27-
## Run Jest tests
104+
# SourcedBranch
28105
npm run test
106+
displayName: Run Tests
29107
env:
30108
# NPM Token variable if using private NPM repository for packages
31109
# NPM_TOKEN: $(NPM_TOKEN) #uncomment to use
32110
# NetSuite Secret Token within Azure Library/Variables
33111
ENV_TOKENSECRET: $(TOKENSECRET)
112+
ENV_TOKENID: $(TOKENID)
34113
# 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)
114+
NPM_TOKEN: $(NPM_TOKEN)
115+
failTaskOnFailedTests: true
116+
117+
# - task: PublishTestResults@2
118+
# inputs:
119+
# testResultsFormat: 'JUnit'
120+
# testResultsFiles: '**/test-report*.xml'
121+
# testRunTitle: 'NetSuite Repo Tests'
122+
# displayName: Publish Test Results
123+
# condition: always()
124+
125+
# - task: CopyFiles@2
126+
# inputs:
127+
# contents: |
128+
# **/.build/**
129+
# !**/node_modules/**
130+
# !**/.vscode/**
131+
# !**/docs/**
132+
# !**/resources/**
133+
# !**/__tests__/**
134+
# targetFolder: $(Build.ArtifactStagingDirectory)
135+
# displayName: Stage Build Artifact
136+
137+
# - task: PublishBuildArtifacts@1
138+
# inputs:
139+
# pathToPublish: $(Build.ArtifactStagingDirectory)
140+
# artifactName: Build-$(BuildLabel)
141+
# displayName: Publish Build Artifact
142+
143+
# - script: |
144+
# echo "##vso[build.addbuildtag]$(BuildLabel)"
145+
# displayName: Add Build Tag
146+
# condition: and(succeeded(), eq(variables['RELEASE_BUILD'], 'true'))
147+
# env:
148+
# SYSTEM_ACCESSTOKEN: $(System.AccessToken)
149+
150+
- task: PowerShell@2
151+
inputs:
152+
targetType: 'inline'
153+
script: |
154+
155+
## Update Project Release Version based on projects package.json version
156+
$VERSION = "$(cat package.json | grep 'version' | cut -d ':' -f 2 )"
157+
$SAVE_VERSION = $VERSION -replace '"|,',''
158+
$VariableGroupId = GROUP_ID_NUMBER
159+
$NewValue = $SAVE_VERSION
160+
$VariableName = NetSuite_version"
161+
162+
Write-Host "NewValue : $NewValue"
163+
164+
$url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/distributedtask/variablegroups/$($VariableGroupId)?api-version=5.1-preview.1"
165+
166+
Write-Host "URL: $url"
167+
168+
$authHeader = @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
169+
170+
$definition = Invoke-RestMethod -Uri $url -Headers $authHeader
171+
172+
Write-Host "Pipeline = $($definition | ConvertTo-Json -Depth 100)"
173+
174+
$definition.variables.$VariableName.Value = "$($NewValue)"
175+
176+
$definitionJson = $definition | ConvertTo-Json -Depth 100 -Compress
177+
178+
Invoke-RestMethod -Method Put -Uri $url -Headers $authHeader -ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($definitionJson)) | Out-Null
179+
displayName: Update Project Version
180+
env:
181+
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

0 commit comments

Comments
 (0)