-
Notifications
You must be signed in to change notification settings - Fork 228
/
azure-pipelines.yml
185 lines (161 loc) · 7.14 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
trigger:
- master
pool: .net-bubble-aws-re-team-prod
variables:
- group: sonar-dotnet-variables
- group: sonarsource-build-variables
- group: artifactory_access
# ~https://github.com/SonarSource/re-ci-images/blob/master/docker/mvn/settings-private.xml
- name: ARTIFACTORY_PRIVATE_USERNAME
value: $[variables.ARTIFACTORY_PRIVATE_READER_USERNAME]
- name: ARTIFACTORY_QA_READER_USERNAME
value: $[variables.ARTIFACTORY_PRIVATE_READER_USERNAME]
- name: UnitTestResultsPath
value: '$(Build.SourcesDirectory)\TestResults'
- name: CoveragePath
value: '$(Build.SourcesDirectory)\coverage'
- name: UnitTestExclusionsPattern
value: 'analyzers/tests/SonarAnalyzer.Test/TestCases/**/*'
resources:
repositories:
- repository: pipelines-yaml-templates
type: git
name: pipelines-yaml-templates
ref: refs/tags/v3.0.0
stages:
- stage: build
displayName: 'Build:'
jobs:
- job: build
displayName: 'Build'
workspace:
clean: all
steps:
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- script: '"$(MSBUILD_PATH)" /t:restore /p:RestoreLockedMode=true /p:RestoreConfigFile="analyzers\NuGet.Config" $(solution)'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
displayName: "NuGet Restore"
- powershell: .\scripts\build\store-azp-variables.ps1
displayName: "Store AZP Variables"
- publish: $(Agent.BuildDirectory)/Azp-Variables
artifact: Azp-Variables
displayName: "Publish AZP Variables as pipeline artifact"
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- powershell: .\scripts\set-version.ps1 -Version $(SHORT_VERSION) -BuildNumber $(Build.BuildId) -Branch $(Build.SourceBranchName) -Sha1 $(Build.SourceVersion)
displayName: "Set Version"
- task: SonarCloudPrepare@3
displayName: '.NET Code Analysis - Begin (PR)'
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: dotnet
projectKey: 'sonaranalyzer-dotnet'
projectName: 'Sonar .NET Analyzer'
projectVersion: '$(SHORT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(CoveragePath)/*.xml"
sonar.cs.vstest.reportsPaths="$(UnitTestResultsPath)/*.trx"
sonar.test.exclusions="$(UnitTestExclusionsPattern)"
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(System.PullRequest.SourceCommitId)
sonar.analysis.prNumber=$(System.PullRequest.PullRequestNumber)
sonar.analysis.repository=$(Build.Repository.ID)
- task: SonarCloudPrepare@3
displayName: '.NET Code Analysis - Begin (master or branch)'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: dotnet
projectKey: 'sonaranalyzer-dotnet'
projectName: 'Sonar .NET Analyzer'
projectVersion: '$(SHORT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(CoveragePath)/*.xml"
sonar.cs.vstest.reportsPaths="$(UnitTestResultsPath)/*.trx"
sonar.test.exclusions="$(UnitTestExclusionsPattern)"
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(Build.SourceVersion)
sonar.analysis.repository=$(Build.Repository.ID)
- powershell: |
$ProjectNameToken = '$(ProjectName)' # Workaround for escaping difficulties: Azure DevOps doesn't have ProjectName, so it will not replace it. We need to pass it like that into AltCover via powershell.
dotnet test $(Solution) -c $(BuildConfiguration) -l trx --results-directory $(UnitTestResultsPath) /p:RunAnalyzers=true /p:AltCover=true,AltCoverForce=true,AltCoverVisibleBranches=true,AltCoverAssemblyFilter="testhost|Moq|Humanizer|AltCover|Microsoft|\.Test^",AltCoverPathFilter="SonarAnalyzer\.CFG\\ShimLayer|SonarAnalyzer\.ShimLayer\.CodeGeneration",AltCoverAttributeFilter="ExcludeFromCodeCoverage",AltCoverReport="$(CoveragePath)/coverage.$ProjectNameToken.xml"
dotnet build analyzers\src\RuleDescriptorGenerator\RuleDescriptorGenerator.csproj -c $(BuildConfiguration) /p:RunAnalyzers=true # This does not have a test project => we need to build it separately
displayName: '.Net Build and UTs'
env:
ARTIFACTORY_USER: $(ARTIFACTORY_PRIVATE_READER_USERNAME)
ARTIFACTORY_PASSWORD: $(ARTIFACTORY_PRIVATE_READER_ACCESS_TOKEN)
- task: PublishTestResults@2
condition: always()
displayName: 'Publish test results'
inputs:
testRunner: VSTest
testResultsFiles: '*.trx'
searchFolder: '$(UnitTestResultsPath)'
testRunTitle: '$(Agent.JobName)'
- task: NuGetCommand@2
displayName: "Build NuGet packages"
inputs:
command: pack
packagesToPack: 'analyzers/packaging/*.nuspec'
configuration: '$(BuildConfiguration)'
buildProperties: 'Version=$(FULL_VERSION)'
packDestination: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'Detailed'
publishPackageMetadata: true
- task: SonarCloudAnalyze@3
displayName: '.NET Code Analysis - End'
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: SonarCloudPrepare@3
displayName: 'Prepare code analysis for Java plugin'
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'Other'
- task: Maven@4
displayName: 'Maven build'
inputs:
goals: 'verify'
options: -B --settings $(mavenSettings.secureFilePath) -Pcoverage -Dsonar.projectVersion=$(SHORT_VERSION)
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: '$(Agent.JobName)'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenOptions: $(MAVEN_OPTS)
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- task: CopyFiles@2
displayName: "Copy C# Jars to publish directory"
inputs:
Contents: '*.jar'
SourceFolder: 'sonar-csharp-plugin/target'
TargetFolder: 'plugin-jars/sonar-csharp-plugin'
- task: CopyFiles@2
displayName: "Copy VB.NET Jars to publish directory"
inputs:
Contents: '*.jar'
SourceFolder: 'sonar-vbnet-plugin/target'
TargetFolder: 'plugin-jars/sonar-vbnet-plugin'
- publish: plugin-jars
artifact: plugin-jars
displayName: "Publish Jars as build artifacts"
- publish: '$(Build.ArtifactStagingDirectory)/packages'
artifact: 'NuGet Packages'
displayName: 'Publish NuGet packages as build artifacts'
- task: SonarCloudPublish@3
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'