forked from kimcuhoang/ddd-net-ef-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
137 lines (121 loc) · 3.85 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
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- cake/*
pr:
autoCancel: true
branches:
include:
- master
pool:
vmImage: 'ubuntu-16.04'
variables:
buildConfiguration: 'Release'
NETCoreVersion: '3.1.x'
solutionFile: '$(Build.SourcesDirectory)/*.sln'
unitTestPath: '$(Build.SourcesDirectory)/source/productcatalog/test'
unitTestProjects: '$(unitTestPath)/*Tests/*.csproj'
codeCoverageReportPath : '$(Build.SourcesDirectory)/CodeCoverage'
sqlPassword: 'P@ssword'
stages:
- stage: RunBuild
displayName: 'Run Build'
jobs:
- job: BuildJob
steps:
#############
# Install .net core
#############
- task: UseDotNet@2
displayName: "Install .NET Core $(NETCoreVersion)"
inputs:
version: '$(NETCoreVersion)'
#############
# dotnet restore solution
#############
- task: DotNetCoreCLI@2
displayName: "dotnet restore"
inputs:
command: 'restore'
projects: '$(solutionFile)'
#############
# dotnet build solution
#############
- task: DotNetCoreCLI@2
displayName: "dotnet build"
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: '$(solutionFile)'
- stage: RunTests
displayName: 'Run Tests'
jobs:
- job: RunTestsJob
displayName: 'Run Tests Projects'
steps:
- script: |
docker run -d -p 1433:1433 -e 'SA_PASSWORD=$(sqlPassword)' -e 'ACCEPT_EULA=Y' mcr.microsoft.com/mssql/server:2019-latest
displayName: 'Start docker'
- script: printenv
- script: |
docker ps -a
displayName: "List all running containers"
- script: |
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
displayName: 'Install SqlCommand tool for Linux'
- script: |
sqlcmd -S localhost -U sa -P $(sqlPassword) -Q "SELECT @@VERSION"
displayName: 'Test SqlConnection'
- script: |
dotnet --list-sdks
displayName: 'List all installed sdks'
- task: UseDotNet@2
displayName: "Install .NET Core $(NETCoreVersion)"
inputs:
version: '$(NETCoreVersion)'
#############
# dotnet test
#############
- task: DotNetCoreCLI@2
displayName: "dotnet test"
inputs:
command: test
projects: '$(unitTestProjects)'
arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
nobuild: true
- script: |
dotnet tool install -g dotnet-reportgenerator-globaltool --version 4.3.8
$HOME/.dotnet/tools/reportgenerator -reports:$(unitTestPath)/**/coverage.cobertura.xml -targetdir:$(codeCoverageReportPath) -reporttypes:Cobertura
displayName: 'Create Code coverage report'
- task: PublishCodeCoverageResults@1
continueOnError: true
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(codeCoverageReportPath)/Cobertura.xml'
reportDirectory: '$(codeCoverageReportPath)'
failIfCoverageEmpty: true
- script: |
docker container stop $(docker container ls -aq)
docker container rm $(docker container ls -aq)
displayName: 'Stop all container & Clean up'
continueOnError: true
- stage: CleanUp
displayName: "Cleanup After Build"
jobs:
- job: "CleanUpJob"
steps:
- task: DeleteFiles@1
continueOnError: true
inputs:
SourceFolder: '$(Agent.BuildDirectory)'
Contents: '**/*'
RemoveSourceFolder: true