-
Notifications
You must be signed in to change notification settings - Fork 1
/
azure-pipelines.yml
135 lines (118 loc) · 4.59 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
trigger:
- master
- release/*
- hotfix/*
- bugfix/*
- refactor/*
pool:
vmImage: 'ubuntu-latest'
variables:
project_name: 'ProductManager'
netcore_version: '3.1'
sonarcloud_project: 'brunovitorprado_ProductManager'
sonarcloud_organization: 'brunovitorprado'
sonarcloud_account: 'ProductManager'
docker_image_name: 'brunomcp2010/productmanager-api'
docker_registry_account: 'productmanager-api'
isMasterBranch: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
jobs:
- job: Build
steps:
- script: ##vso[task.setvariable variable=sonarcloud_account;] $(TESTE)
condition: and(succeeded(), eq(variables.isMasterBranch, 'true'))
name: SetVars
- script: echo $(sonarcloud_account)
- script: |
pwd && ls -la
dotnet restore $(project_name)
dotnet publish $(project_name) -c Release -o bin/Release/netcoreapp$(netcore_version)
mkdir artifact
cp -r $(System.DefaultWorkingDirectory)/bin/Release/netcoreapp$(netcore_version) artifact/$(Build.SourceBranchName)
displayName: Build Application
- task: PublishPipelineArtifact@1
displayName: Store Application Artifact
inputs:
path: $(System.DefaultWorkingDirectory)/artifact
artifact: $(project_name)
- job: UnityTests
dependsOn: Build
steps:
- script: |
dotnet tool install --global coverlet.console
dotnet add $(project_name)/$(project_name).Test/$(project_name).Test.csproj package coverlet.msbuild
dotnet add $(project_name)/$(project_name).Test/$(project_name).Test.csproj package XunitXml.TestLogger
dotnet test /p:CollectCoverage=true \
/p:CoverletOutputFormat=\"opencover,cobertura\" \
/p:CoverletOutput=results/result \
/p:Exclude=[xunit.*]* $(project_name)/$(project_name).sln \
--test-adapter-path:. --logger:"xunit;LogFilePath=results/result.xunit.xml"
displayName: Runnig Unit Tests
- task: PublishPipelineArtifact@1
displayName: Store Test Result
inputs:
path: $(System.DefaultWorkingDirectory)/$(project_name)/$(project_name).Test/results
artifact: UnitTestResults
- task: PublishCodeCoverageResults@1
displayName: Publish Code Coverage
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: $(System.DefaultWorkingDirectory)/$(project_name)/$(project_name).Test/results/result.cobertura.xml
pathToSources: .
failIfCoverageEmpty: true
- task: PublishTestResults@2
displayName: Publish Test Result
inputs:
testResultsFormat: 'XUnit'
testResultsFiles: '$(System.DefaultWorkingDirectory)/$(project_name)/$(project_name).Test/results/result.xunit.xml'
testRunTitle: Collecting Test Results
- job: QualityAnalysis
dependsOn: UnityTests
steps:
- task: DownloadPipelineArtifact@2
displayName: Get Test Results
inputs:
artifact: UnitTestResults
- task: SonarCloudPrepare@1
inputs:
SonarCloud: '$(sonarcloud_account)'
organization: '$(sonarcloud_organization)'
scannerMode: 'MSBuild'
projectKey: '$(sonarcloud_project)'
projectName: '$(project_name)'
extraProperties: |
sonar.cs.opencover.reportsPaths=$(Pipeline.Workspace)/result.opencover.xml
sonar.coverage.exclusions=$(project_name)/$(project_name).Api/**/*.*,$(project_name)/$(project_name).Infrastructure/**/*.*,$(project_name)/$(project_name).IoC/**/*.*
- script: |
dotnet build $(project_name)
displayName: Runing Build for Analysis
- task: SonarCloudAnalyze@1
displayName: Finish Sonar Analysis
- task: SonarCloudPublish@1
displayName: Publish quality gate results
inputs:
pollingTimeoutSec: '300'
- job: PublishDockerImage
dependsOn: QualityAnalysis
condition: and(succeeded(), variables['Build.SourceBranch'], 'refs/heads/master')
variables:
Version: '$(Build.BuildNumber)'
steps:
- task: DownloadPipelineArtifact@2
displayName: Get Application Artifact
inputs:
artifact: $(project_name)
- script: |
mkdir -p $(project_name)/bin/Release
cp -r $(Pipeline.Workspace)/$(Build.SourceBranchName) $(project_name)/bin/Release/netcoreapp$(netcore_version)
displayName: Prepare Files
- task: Docker@2
displayName: 'Build and Publish Docker Image'
inputs:
containerRegistry: '$(docker_registry_account)'
repository: '$(docker_image_name)'
command: 'buildAndPush'
Dockerfile: '$(System.DefaultWorkingDirectory)/api.dockerfile'
buildContext: '$(System.DefaultWorkingDirectory)'
tags: |
$(Version)
latest