forked from ThiagoBarradas/environment-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
109 lines (104 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
variables:
project_name: 'EnvironmentApi'
netcore_version: '2.2'
relative_path_publish: 'bin/Release/netcoreapp'
relative_path_copy: '/bin/Release/netcoreapp'
sonarcloud_project: 'RenasTI_Environment_API'
sonarcloud_organization: 'renasti-github'
sonarcloud_account: 'testeSonar'
docker_image_name: 'renasti/environment-api'
docker_registry_account: 'DockerRegistryRenasTI'
name: 1.0$(rev:.r)
jobs:
- job: Build
steps:
- script: |
pwd && ls -la
dotnet restore
dotnet publish -c Release -o $(relative_path_publish)$(netcore_version)
mkdir artifact
cp -r $(project_name)/$(relative_path_copy)$(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: SonarAnalysis
dependsOn: UnitTests
steps:
- task: DownloadPipelineArtifact@2
displayName: Get Test Result
inputs:
artifact: UnitTestResults
- task: SonarQubePrepare@4
inputs:
SonarQube: 'testeSonar'
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: SonarQubeAnalyze@4
displayName: Finish Sonarqube Analysis
- task: SonarQubePublish@4
inputs:
pollingTimeoutSec: '300'
- job: PublishDockerImage
dependsOn: SonarAnalysis
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)/Dockerfile'
buildContext: '$(System.DefaultWorkingDirectory)'
tags: |
$(Version)
latest