-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
157 lines (137 loc) · 5.05 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Node.js Function App to Linux on Azure
# Build a Node.js function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
branches:
include:
- main
pr:
branches:
include:
- main
variables:
# Function app name
functionApp1Name: 'owner-community-data-access-west2'
functionApp2Name: 'owner-community-data-access-east2'
# Environment name
environmentName: 'data-access'
# Agent VM image name
vmImageName: 'ubuntu-latest'
system.debug: true
npm_config_cache: $(Pipeline.Workspace)/.npm
SONAR_USER_HOME: $(Pipeline.Workspace)/.sonar
pool:
# Ensure OS we build on is same as what we run the function on.
vmImage: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
# Ensure the correct version of Node is installed.
- task: NodeTool@0
displayName: 'Install: Node.js - LTS'
inputs:
versionSpec: '16.x'
# Ensure the correct version of function tools are installed.
- task: FuncToolsInstaller@0
displayName: 'Install: func tools - latest'
# Cache NPM packages to speed up build process.
- task: Cache@2
displayName: 'NPM: Restore Cache'
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.SourcesDirectory)/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
# Build project and run tests
- task: Bash@3
displayName: 'NPM: Prepare binaries and run tests'
inputs:
targetType: 'inline'
script: |
export NODE_OPTIONS=--max_old_space_size=16384
npm ci
npm run test:ci
npm run build:production
# Cache SonarCloud downloaded assets to speed up build process.
- task: Cache@2
displayName: 'SonarCloud: Restore Cache'
inputs:
key: 'sonarcloud | "$(Agent.OS)"'
restoreKeys: |
sonarcloud | "$(Agent.OS)"
path: $(SONAR_USER_HOME)/cache
# Set up SonarCloud
- task: SonarCloudPrepare@1
displayName: 'SonarCloud: Prepare analysis configuration'
inputs:
SonarCloud: 'sonarcloud'
organization: 'simnova'
scannerMode: 'CLI'
configMode: 'manual'
cliProjectKey: 'simnova_ownercommuntiy-data-access'
cliProjectName: 'simnova_ownercommuntiy-data-access'
cliSources: './'
extraProperties: |
sonar.javascript.lcov.reportPaths=$(System.DefaultWorkingDirectory)/coverage/lcov.info
# SonarCloud: Analyze code and code coverage
- task: SonarCloudAnalyze@1
displayName: 'SonarCloud: Run analysis'
# SonarCloud: Publish analysis results and wait until completion
- task: SonarCloudPublish@1
displayName: 'SonarCloud: Publish results on build summary'
inputs:
pollingTimeoutSec: '300'
# Package compiled assets into artifact
- task: ArchiveFiles@2
displayName: 'Artifact: Prepare'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
# Upload artifact as build result
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
displayName: 'Artifact: Publish'
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
artifact: drop
- stage: Deploy
displayName: 'Deploy stage'
dependsOn: Build
condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure Functions App Deploy: $(functionApp1Name)'
inputs:
azureSubscription: 'OwnerCommunity'
appType: 'functionAppLinux'
appName: $(functionApp1Name)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'NODE|16'
deploymentMethod: 'runFromPackage'
- task: AzureFunctionApp@1
displayName: 'Azure Functions App Deploy: $(functionApp2Name)'
inputs:
azureSubscription: 'OwnerCommunity'
appType: 'functionAppLinux'
appName: $(functionApp2Name)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'NODE|16'
deploymentMethod: 'runFromPackage'