-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathazure-pipelines.yml
executable file
·265 lines (215 loc) · 8 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java
trigger:
- main
- releases/*
pool:
vmImage: 'ubuntu-latest'
variables:
#API_VERSION: "apigeeapi"
# or
API_VERSION: "googleapi"
DEFAULT_APIGEE_ENV: "default-dev"
DEFAULT_APIGEE_ORG: "bap-emea-apigee-5"
TEST_HOST: 34.117.38.184.nip.io
#TEST_HOST: "$(APIGEE_ORG)-$(APIGEE_ENV).apigee.net"
AUTHOR_EMAIL: $(APIGEE_USER)
COMMIT_ID: $(Build.SourceVersion)
COMMIT_BRANCH: $(Build.SourceBranch)
# GCP_SERVICE_ACCOUNT, APIGEE_USER & APIGEE_PASSWORD are stored in Azure Pipeline variable settings
steps:
# Set Deployment Target: Define Apigee organization and environmnet from Git Branch
- bash: |
echo $COMMIT_BRANCH is commited
if [ $COMMIT_BRANCH == "refs/heads/prod" ]; then
# Prod branch --> Apigee prod environment
echo "##vso[task.setvariable variable=APIGEE_ORG]$DEFAULT_APIGEE_ORG"
echo "##vso[task.setvariable variable=APIGEE_ENV]prod"
else
# all ohers branches --> default environment
echo "##vso[task.setvariable variable=APIGEE_ORG]$DEFAULT_APIGEE_ORG"
echo "##vso[task.setvariable variable=APIGEE_ENV]$DEFAULT_APIGEE_ENV"
fi
enabled: "true"
displayName: Set Deployment Target
env:
DEFAULT_APIGEE_ORG: $(DEFAULT_APIGEE_ORG)
DEFAULT_APIGEE_ENV: $(DEFAULT_APIGEE_ENV)
COMMIT_BRANCH: $(COMMIT_BRANCH)
# install node.js tools and dependencies
- task: NodeTool@0
inputs:
versionSpec: '12.x'
enabled: "true"
- task: Npm@1
inputs:
command: 'install'
workingDir: '.'
displayName: npmInstalls
enabled: "true"
# Validate Specification file (OAS, Swagger) using Stoplight Spectral
# + upload artifact (spectral-report.html)
- bash: |
echo "run Stoplight Spectral"
mkdir OAS_test_output
./node_modules/.bin/spectral lint -r ./test/spectral/.spectral.yaml -f html -o ./OAS_test_output/spectral-report.html ./specs/airport-1.0.0.yaml || true # catch all errors for demo purpose
enabled: "true"
displayName: runSpectralScan
# Publish Spectral scan folder results
- task: PublishBuildArtifacts@1
displayName: publishStaticCodeTestsResults
enabled: "true"
inputs:
pathToPublish: OAS_test_output
artifactName: OAS_test
# run Apigeelint, API proxy linter
# generate result output in Junit because Azure task PublishTestResults doesn't (yet) support html
- bash: |
echo "run Apigeelint"
mkdir code_test_output
./node_modules/apigeelint/cli.js -s apiproxy/ -e PO013 -f html.js > code_test_output/apigeelint-output.html
enabled: "true"
displayName: runApigeeLint
# run ESlint, javascript linter
- bash: |
echo "run Eslint"
./node_modules/eslint/bin/eslint.js -c ./.eslintrc-jsc.yml --format html ./apiproxy/resources/jsc > code_test_output/eslint-out.html
cat code_test_output/eslint-out.html
enabled: "true"
displayName: runESlint
# Publish static code analysis folder results
- task: PublishBuildArtifacts@1
displayName: publishStaticCodeTestsResults
enabled: "true"
inputs:
pathToPublish: code_test_output
artifactName: static-code-analysis
# run Mocha, JavaScript unit test
- bash: |
echo "run Mocha"
mkdir unit_test_output
./node_modules/nyc/bin/nyc.js --reporter=html --reporter=html ./node_modules/mocha/bin/_mocha ./test/unit
cp ./coverage/* ./unit_test_output
enabled: "true"
displayName: runMocha
# Publish unit test folder results
- task: PublishBuildArtifacts@1
displayName: publishUnitTestsResults
enabled: "true"
inputs:
pathToPublish: unit_test_output
artifactName: unit-tests
# Configure EdgeeConfig/edge.json file: update target environment name
- bash: |
sed -i "s/target_apigee_env/$(APIGEE_ENV)/g" ./EdgeConfig/edge.json
enabled: "true"
displayName: Update edge.json
# Generate GCP Service Account file from Azure Pipeline variable GCP_SERVICE_ACCOUNT
# if deploy to Apigee X/hybrid
- bash: |
echo '$(GCP_SERVICE_ACCOUNT)' > sa.json
enabled: "true"
condition: and(succeeded(), eq(variables.API_VERSION, 'googleapi'))
displayName: Generate SA Key file
env:
GCP_SERVICE_ACCOUNT: $(GCP_SERVICE_ACCOUNT)
# Maven Deploy Apigee Configuration (from EdgeeConfig/edge.json): Apigee edge
- task: Maven@3
displayName: mvnApigeeConfigurationApigee
enabled: "true"
condition: and(succeeded(), eq(variables.API_VERSION, 'apigeeapi'))
inputs:
mavenPomFile: './pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "install -P$(API_VERSION) -Dapigee.org=$(APIGEE_ORG) -Denv=$(APIGEE_ENV) -Dapigee.username=$(APIGEE_USER) -Dapigee.password=$(APIGEE_PASSWORD) -Dapigee.config.file=EdgeConfig/edge.json -Dapigee.config.options=update"
env:
APIGEE_PASS: $(APIGEE_PASS)
# Maven Deploy Apigee Configuration (from EdgeeConfig/edge.json): Apigee X/hybrid
- task: Maven@3
displayName: mvnApigeeConfigurationGoogle
enabled: "true"
condition: and(succeeded(), eq(variables.API_VERSION, 'googleapi'))
inputs:
mavenPomFile: './pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "install -P$(API_VERSION) -Dapigee.org=$(APIGEE_ORG) -Denv=$(APIGEE_ENV) -Dsa=sa.json -Dapigee.config.file=./EdgeConfig/edge.json -Dapigee.config.options=update"
# Maven Config Env.
- task: Maven@3
displayName: mvnProcessResources
enabled: "true"
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "process-resources -P$(API_VERSION) -Dcommit=$(GIT_COMMIT) -Dbranch=$(GIT_BRANCH) -Dauthor=$(AUTHOR_EMAIL) -e"
# Maven Package proxy bundle
- task: Maven@3
displayName: mvnApigeeConfigure
enabled: "true"
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "apigee-enterprise:configure -P$(API_VERSION) -Dorg=$(APIGEE_ORG) -Denv=$(APIGEE_ENV)"
# Maven Deploy proxy bundle: Apigee Edge
- task: Maven@3
displayName: mvnApigeeDeployApigee
enabled: "true"
condition: and(succeeded(), eq(variables.API_VERSION, 'apigeeapi'))
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "apigee-enterprise:deploy -P$(API_VERSION) -Dorg=$(APIGEE_ORG) -Denv=$(APIGEE_ENV) -Dpassword=$(APIGEE_PASSWORD) -Dusername=$(APIGEE_USER)"
env:
APIGEE_PASS: $(APIGEE_PASS)
# Maven Deploy proxy bundle: Apigee X/hybrid
- task: Maven@3
displayName: mvnApigeeDeployGoogle
enabled: "true"
condition: and(succeeded(), eq(variables.API_VERSION, 'googleapi'))
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
goals: "apigee-enterprise:deploy -P$(API_VERSION) -Dapigee.org=$(APIGEE_ORG) -Denv=$(APIGEE_ENV) -Dsa=sa.json"
# run Apickli, API test integration
- bash: |
echo "run Apickli"
mkdir integration_output
export NODE_TLS_REJECT_UNAUTHORIZED="0"
sed -i "s/organization_hostname/$TEST_HOST/g" ./test/integration/features/support/init.js
node ./node_modules/cucumber/bin/cucumber-js ./test/integration --format json:report.json
node ./test/integration/index.js
cp ./cucumber_report.html integration_output/apickli_report.html
displayName: runApickli
enabled: "true"
# Publish integration test folder result
- task: PublishBuildArtifacts@1
displayName: publishInteegrationTestsResults
enabled: "true"
inputs:
pathToPublish: integration_output
artifactName: integration-tests