-
Notifications
You must be signed in to change notification settings - Fork 32
/
4-build-test-qa-dockerpublish.yml
117 lines (113 loc) · 4.06 KB
/
4-build-test-qa-dockerpublish.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
variables:
project_name: 'EnvironmentApi'
netcore_version: '2.2'
sonarcloud_project: 'ThiagoBarradas_environment-api'
sonarcloud_organization: 'thiagobarradas-github'
sonarcloud_account: 'SonarCloudBarradas'
docker_image_name: 'thiagobarradas/environment-api'
docker_registry_account: 'DockerRegistryBarradas'
jobs:
- job: Build
steps:
- script: |
pwd && ls -la
dotnet restore
dotnet publish -c Release -o bin/Release/netcoreapp$(netcore_version)
mkdir artifact
cp -r $(project_name)/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: UnitTests
dependsOn: Build
steps:
- script: |
dotnet tool install --global coverlet.console
dotnet add $(project_name).Tests/$(project_name).Tests.csproj package coverlet.msbuild
dotnet add $(project_name).Tests/$(project_name).Tests.csproj package XunitXml.TestLogger
dotnet test /p:CollectCoverage=true \
/p:CoverletOutputFormat=\"opencover,cobertura\" \
/p:CoverletOutput=results/result \
/p:Exclude=[xunit.*]* $(project_name).sln \
--test-adapter-path:. --logger:"xunit;LogFilePath=results/result.xunit.xml"
displayName: Running Unit Tests
- task: PublishPipelineArtifact@1
displayName: Store Test Result
inputs:
path: $(System.DefaultWorkingDirectory)/$(project_name).Tests/results
artifact: UnitTestResults
- task: PublishCodeCoverageResults@1
displayName: Publish Code Coverage
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: $(System.DefaultWorkingDirectory)/$(project_name).Tests/results/result.cobertura.xml
pathToSources: .
failIfCoverageEmpty: true
- task: PublishTestResults@2
displayName: Publish Test Result
inputs:
testResultsFormat: 'XUnit'
testResultsFiles: '$(System.DefaultWorkingDirectory)/$(project_name).Tests/results/result.xunit.xml'
testRunTitle: 'Collecting Test Results'
- job: QualityAnalysis
dependsOn: UnitTests
steps:
- task: DownloadPipelineArtifact@2
displayName: Get Test Result
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'
- script: |
dotnet build
displayName: Runnig Build For Analysis
- task: SonarCloudAnalyze@1
displayName: Finish Sonarqube Analysis
- task: SonarCloudPublish@1
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: replacetokens@3
inputs:
targetFiles: 'Dockerfile'
encoding: 'auto'
writeBOM: true
verbosity: 'detailed'
actionOnMissing: 'warn'
keepToken: true
tokenPrefix: '__['
tokenSuffix: ']__'
displayName: Add Version as Env Var
- task: Docker@2
displayName: 'Build and Publish Docker Image'
inputs:
containerRegistry: '$(docker_registry_account)'
repository: '$(docker_image_name)'
command: 'buildAndPush'
Dockerfile: '$(System.DefaultWorkingDirectory)/Dockerfile'
buildContext: '$(System.DefaultWorkingDirectory)'
tags: |
$(Version)
latest