-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
293 lines (259 loc) · 10.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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
name: $(GitVersion.SemVer)
parameters:
- name: BuildConfiguration
displayName: Release or Debug
type: string
default: Release
values:
- Release
- Debug
resources:
- repo: self
fetchDepth: 30
variables:
BuildPlatform: 'Any CPU'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
workspace:
clean: all
variables:
"Nuget.Feed": 'dct-pkg'
"Nuget.Version": '5.3.0'
"DotnetCore.Version": '2.2.x'
pool:
name: DCT
demands:
- IsBuildServer
steps:
- task: UseDotNet@2
displayName: 'Use .NET Core sdk : $(DotnetCore.Version)'
inputs:
packageType: sdk
version: $(DotnetCore.Version)
performMultiLevelLookup: true
# - task: NuGetToolInstaller@0
# displayName: 'Use NuGet : $(Nuget.Version)'
# inputs:
# versionSpec: '> $(Nuget.Version)'
# checkLatest: true
- task: gittools.gitversion.gitversion-task.GitVersion@4
displayName: use Git Version to generate build number
inputs:
updateAssemblyInfo: true
preferBundledVersion: false
- task: UseNode@1
enabled: false
displayName: 'Use Node 12.x'
inputs:
version: 12.x
checkLatest: true
# Generate the report using ReportGenerator (https://github.com/danielpalme/ReportGenerator)
# First install the tool on the machine, then run it
- script: dotnet tool update dotnet-reportgenerator-globaltool --version 4.3.6
displayName: Install/update dotnet-reportgenerator-globaltool
continueOnError: true
enabled: false
- task: DeleteFiles@1
displayName: 'Delete appsettings.Development.json'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
Contents: |
**/appsettings.Development.json
#********************************************************************************
# Display Variables
#********************************************************************************
- task: PowerShell@2
enabled: true
name: DislayAllVariables2
displayName: 'Display all variables'
continueOnError: true
inputs:
targetType: 'inline'
script: |
(gci env:*).GetEnumerator() | Sort-Object Name | ForEach {Write-Host "Name: $($_.Name) | Value : $($_.Value)"}
#********************************************************************************
# Build and Restore
#********************************************************************************
- task: Npm@1
displayName: 'NPM Install'
enabled: false
inputs:
command: 'install'
workingDir: '$(Build.SourcesDirectory)/ESFA.DC.SubmitLearnerData.API.Public'
verbose: false
- task: DotNetCoreCLI@2
displayName: 'Restore Nuget packages'
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
vstsFeed: $(Nuget.Feed)
noCache: true
- task: DotNetCoreCLI@2
displayName: Build Projects
inputs:
workingDirectory: "$(Build.SourcesDirectory)/"
projects: '**/*.csproj'
command: build
arguments: "--configuration ${{ parameters.BuildConfiguration }} --no-restore -p:version=$(Build.BuildNumber) -p:FileVersion=$(Build.BuildNumber)"
#********************************************************************************
# Copy Nuget Packages into Aftifact Folder before test.
#********************************************************************************
- task: CopyFiles@2
displayName: 'Copy Nuget Interface Packages Files - Artifact NugetInterface Directory'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: |
**\*$(Build.Configuration)*\*Interface.nupkg
!**\packages\**
!**\bin\x64\**
TargetFolder: '$(build.artifactstagingdirectory)\Nuget\Interface'
CleanTargetFolder: true
flattenFolders: true
- task: CopyFiles@2
displayName: 'Copy NugetPackages Files - Artifact NugetPackages Directory'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: |
**\${{ parameters.BuildConfiguration }}\*.nupkg
!**\packages\**
!**\bin\x64\**
TargetFolder: '$(build.artifactstagingdirectory)\Nuget\Packages'
CleanTargetFolder: true
flattenFolders: true
#********************************************************************************
# Package Web Application
#********************************************************************************
- task: DotNetCoreCLI@2
displayName: 'Package Api Artifact Folder'
inputs:
command: publish
publishWebProjects: false
zipAfterPublish: true
nobuild: true
projects: '**/*.API.Public.csproj'
arguments: '--configuration ${{ parameters.BuildConfiguration }} --no-build -p:version="$(Build.BuildNumber)" -p:FileVersion="$(Build.BuildNumber)" --output "$(Build.ArtifactStagingDirectory)\Web\API"'
#********************************************************************************
# SQL database Project Build and Acopy to Artifact Directory
#********************************************************************************
- task: MSBuild@1
enabled: false
displayName: 'Build SQL database Project'
inputs:
solution: '**/*.Operations.AuditDatabase.sqlproj'
configuration: '${{ parameters.BuildConfiguration }}'
msbuildArguments: '-p:version=$(Build.BuildNumber) -p:FileVersion=$(Build.BuildNumber) -p:SkipInvalidConfigurations=true'
maximumCpuCount: true
clean: false
restoreNugetPackages: false
logProjectEvents: true
createLogFile: true
- task: CopyFiles@2
enabled: false
displayName: 'Copy Database Files - Artifact Databases Directory'
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: |
**\*Database\**\*.dacpac
TargetFolder: '$(build.artifactstagingdirectory)\Databases'
CleanTargetFolder: true
flattenFolders: true
#********************************************************************************
# Count Artifact Files to decide what to Publish
#********************************************************************************
- task: PowerShell@2
enabled: true
displayName: 'Check What to Publish'
continueOnError: true
inputs:
targetType: 'inline'
script: |
Write-Host "##vso[task.setvariable variable=PublishArtifact_Web]$(Test-Path '$(build.artifactstagingdirectory)\Web' -PathType Any)";
Write-Host "##vso[task.setvariable variable=PublishArtifact_NugetPackages]$(Test-Path '$(build.artifactstagingdirectory)\Nuget' -PathType Any)";
Write-Host "##vso[task.setvariable variable=PublishArtifact_Databases]$(Test-Path '$(build.artifactstagingdirectory)\Databases' -PathType Any)";
#********************************************************************************
# Run Unit Tests
#********************************************************************************
# Run all tests with "/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura" to generate the code coverage file
- task: DotNetCoreCLI@2
displayName: Run .net Core Unit Tests
inputs:
command: test
projects: |
**/*Tests.csproj
!**/*.Automation.Tests.csproj
arguments: '--no-build --no-restore --configuration ${{ parameters.BuildConfiguration }} /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
- task: Npm@1
enabled: false
displayName: 'npm test'
inputs:
command: custom
workingDir: 'ESFA.DC.Web.Operations' # location of package.json
verbose: false
customCommand: 'run test'
condition: succeededOrFailed()
#********************************************************************************
# Generate Code Coverage Report and Publish
#********************************************************************************
# need to add Nuget PAckage 'coverlet.msbuild' to Test Projects.
#
## Generate the report using ReportGenerator (https://github.com/danielpalme/ReportGenerator)
# First install the tool on the machine, then run it
- script: |
dotnet tool update -g dotnet-reportgenerator-globaltool --version 4.3.6
reportgenerator -reports:$(Build.SourcesDirectory)/**/*Tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:Cobertura
displayName: Create Code coverage report
enabled: true
# Publish the code coverage result (summary and web site)
# The summary allows to view the coverage percentage in the summary tab
# The web site allows to view which lines are covered directly in Azure Pipeline
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage'
enabled: true
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'
- task: dependency-check-build-task@5
enabled: false
displayName: 'Run OWASP Dependency Check'
inputs:
projectName: 'ESFA.DC.SubmitLearnerData.API.Public'
scanPath: '**/*.*'
format: 'HTML, JUNIT'
reportsDirectory: '$(Build.SourcesDirectory)/OWASP'
- task: PublishTestResults@2
enabled: false
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(Build.SourcesDirectory)/OWASP/**/dependency-check-junit.xml'
mergeTestResults: true
#********************************************************************************
# Publish Artifacts
#********************************************************************************
## Publish Web Artifacts
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: Web'
enabled: True
condition: and(succeeded(), eq(variables['PublishArtifact_Web'], 'True'))
inputs:
ArtifactName: Web
PathtoPublish: '$(build.artifactstagingdirectory)\Web'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: NugetPackages'
enabled: True
condition: and(succeeded(), eq(variables['PublishArtifact_NugetPackages'], 'True'))
inputs:
ArtifactName: NugetPackages
PathtoPublish: '$(build.artifactstagingdirectory)\Nuget'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: Databases'
enabled: True
condition: and(succeeded(), eq(variables['PublishArtifact_Databases'], 'True'))
inputs:
ArtifactName: Databases
PathtoPublish: '$(build.artifactstagingdirectory)\Databases'