forked from SonarSource/sonar-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
632 lines (543 loc) · 22.5 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
schedules:
# Run from Monday to Friday at 5:30 UTC (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/scheduled-triggers?view=azure-devops&tabs=yaml#cron-syntax)
- cron: "30 5 * * 1-5"
displayName: Daily build
branches:
include:
- master
always: true
trigger:
- master
pool: '.Net Bubble - GCP'
variables:
- group: sonar-dotnet-variables-tmp
- group: sonarsource-build-variables
# To make sure we don`t use MsBuild 17.
- name: MsBuildPath
value: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe'
- name: isReleaseBranch
value: ${{ or(eq(variables['Build.SourceBranch'], 'refs/heads/master'), startsWith(variables['Build.SourceBranch'], 'refs/heads/branch-')) }}
- name: vsVersion
value: '17.0'
resources:
repositories:
- repository: pipelines-yaml-templates
type: git
name: pipelines-yaml-templates
ref: refs/tags/v1.0.13
stages:
- template: stage-with-burgr-notifications.yml@pipelines-yaml-templates
parameters:
burgrName: 'build'
burgrType: 'build'
stageName: 'build'
# Build the dotnet analyzers and stage to repox
stageDisplayName: 'Build:'
jobs:
- job: dotnetBuildjob
displayName: 'Build and package'
steps:
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- script: '"${{ variables.MsBuildPath }}" /t:restore /p:RestoreLockedMode=true /p:RestoreConfigFile="analyzers\NuGet.Config" $(solution)'
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
- task: VSBuild@1
displayName: 'Set BranchName, Sha1 and BuildNumber'
inputs:
solution: scripts/version/ChangeVersion.proj
msbuildArgs: '/p:Sha1=$(Build.SourceVersion) /p:BranchName=$(Build.SourceBranchName) /p:BuildNumber=$(Build.BuildId) /p:BuildConfiguration=$(BuildConfiguration)'
vsVersion: $(vsVersion)
- task: DownloadSecureFile@1
displayName: 'Download snk file'
name: snk
inputs:
secureFile: SonarSourceSecret.snk
- task: DownloadSecureFile@1
displayName: 'Download pfx file'
name: pfx
inputs:
secureFile: 'SonarSource-2021-2023.pfx'
- task: VSBuild@1
displayName: "Build and sign SonarAnalyzer solution"
env:
SIGNTOOL_PATH: 'C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.17763.0\\x64\\signtool.exe'
PFX_PASSWORD: $(pfxPassword2021-2023)
PFX_PATH: $(pfx.secureFilePath)
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:DeployExtension=false /p:SignAssembly=$(isReleaseBranch) /p:AssemblyOriginatorKeyFile="$(snk.secureFilePath)" /p:Sha1=$(Build.SourceVersion) /p:BuildNumber=$(Build.BuildId) /p:WarningLevel=0'
vsVersion: $(vsVersion)
- task: NuGetCommand@2
displayName: "Build NuGet packages"
inputs:
command: pack
packagesToPack: 'analyzers/src/**/*.nuspec;analyzers/packaging/*.nuspec'
configuration: '$(BuildConfiguration)'
packDestination: '$(Build.ArtifactStagingDirectory)/packages'
verbosityPack: 'Detailed'
publishPackageMetadata: true
- task: NuGetCommand@2
displayName: "Sign NuGet packages"
condition: eq(variables.isReleaseBranch, 'True')
inputs:
command: 'custom'
arguments: 'sign $(Build.ArtifactStagingDirectory)\packages\*.nupkg -CertificatePath $(pfx.secureFilePath) -CertificatePassword $(pfxPassword2021-2023) -Timestamper http://sha256timestamp.ws.symantec.com/sha256/timestamp'
- task: PublishBuildArtifacts@1
displayName: 'Publish NuGet packages as build artifacts'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/packages'
artifactName: 'NuGet Packages'
- task: ArtifactoryNuGet@1
displayName: 'Publish SonarAnalyzer.CFG.CSharp NuGet on repox'
inputs:
command: 'push'
artifactoryService: 'Repox artifactory'
targetDeployRepo: '$(ARTIFACTORY_NUGET_REPO)'
pathToNupkg: '$(Build.ArtifactStagingDirectory)/packages/SonarAnalyzer.CFG.CSharp.*.nupkg'
- task: PublishPipelineArtifact@1
displayName: 'Publish analyzer binaries as pipeline artifact'
inputs:
path: analyzers/packaging/binaries/
artifact: Binaries
- task: PublishPipelineArtifact@1
displayName: 'Publish analyzer test binaries as pipeline artifact'
inputs:
path: analyzers\tests\SonarAnalyzer.UnitTest\bin
artifact: TestBinaries
- task: PublishPipelineArtifact@1
displayName: 'Publish rule descriptor binaries as pipeline artifact'
inputs:
path: analyzers\src\SonarAnalyzer.RuleDescriptorGenerator\bin
artifact: RuleDescriptorBin
- template: stage-with-burgr-notifications.yml@pipelines-yaml-templates
parameters:
burgrName: 'qa'
burgrType: 'qa'
stageName: 'qa'
# .NET code analysis, UTs, ITs, build Java and publish SC QG
stageDisplayName: 'Tests:'
stageDependencies: build
jobs:
- job: runUnitTestsJobNet48
displayName: '.NET 4.8 UTs'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download binaries to test'
inputs:
artifact: TestBinaries
targetPath: 'analyzers\tests\SonarAnalyzer.UnitTest\bin'
- powershell: |
. .\scripts\utils.ps1
CreateFolder("coverage")
CreateFolder("TestResults")
& OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net48\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net48.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
Test-ExitCode "ERROR: Unit tests for net48 FAILED."
displayName: '.Net UTs'
- task: PublishPipelineArtifact@1
displayName: 'Save coverage files'
inputs:
path: 'coverage'
artifact: DotnetCoverageNet48
- task: PublishPipelineArtifact@1
displayName: 'Save test results files'
inputs:
path: 'TestResults'
artifact: DotnetTestResultsNet48
- job: runUnitTestsJobNet6
displayName: '.NET 6 UTs'
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download binaries to test'
inputs:
artifact: TestBinaries
targetPath: 'analyzers\tests\SonarAnalyzer.UnitTest\bin'
- powershell: |
. .\scripts\utils.ps1
CreateFolder("coverage")
CreateFolder("TestResults")
& OpenCover.Console.exe -target:"dotnet.exe" -targetargs:"test analyzers\tests\SonarAnalyzer.UnitTest\bin\$(BuildConfiguration)\net6.0\SonarAnalyzer.UnitTest.dll -l trx -l console;verbosity=detailed" -returntargetcode -filter:"+[SonarAnalyzer.CFG]* +[SonarAnalyzer]* +[SonarAnalyzer.CSharp]* +[SonarAnalyzer.Utilities]* +[SonarAnalyzer.VisualBasic]*" -output:coverage/net6.0.xml -safemode:off -excludebyattribute:*.ExcludeFromCodeCoverageAttribute
Test-ExitCode "ERROR: Unit tests for net6.0 FAILED."
displayName: '.Net UTs'
- task: PublishPipelineArtifact@1
displayName: 'Save coverage files'
inputs:
path: 'coverage'
artifact: DotnetCoverageNet6
- task: PublishPipelineArtifact@1
displayName: 'Save test results files'
inputs:
path: 'TestResults'
artifact: DotnetTestResultsNet6
- job: dotNetAnalysis
displayName: '.Net Analysis'
# This job runs the .Net code analysis and uploads to SonarCloud the test results and coverage reports generated
# in previous jobs.
dependsOn:
- runUnitTestsJobNet48
- runUnitTestsJobNet6
steps:
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: SonarCloudPrepare@1
displayName: 'Code Analysis - Begin (PR)'
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'MSBuild'
projectKey: 'sonaranalyzer-dotnet'
projectName: 'SonarAnalyzer .Net'
projectVersion: '$(SONAR_PROJECT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(Build.SourcesDirectory)/coverage/**.xml"
sonar.cs.vstest.reportsPaths="$(Build.SourcesDirectory)/TestResults/*.trx"
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@1
displayName: 'Code Analysis - Begin (master or branch)'
condition: ne(variables['Build.Reason'], 'PullRequest')
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'MSBuild'
projectKey: 'sonaranalyzer-dotnet'
projectName: 'SonarAnalyzer .Net'
projectVersion: '$(SONAR_PROJECT_VERSION)'
extraProperties: |
sonar.verbose=true
sonar.cs.opencover.reportsPaths="$(Build.SourcesDirectory)/coverage/**.xml"
sonar.cs.vstest.reportsPaths="$(Build.SourcesDirectory)/TestResults/*.trx"
sonar.analysis.buildNumber=$(Build.BuildId)
sonar.analysis.pipeline=$(Build.BuildId)
sonar.analysis.sha1=$(Build.SourceVersion)
sonar.analysis.repository=$(Build.Repository.ID)
- task: VSBuild@1
displayName: 'Set BranchName, Sha1 and BuildNumber properties from Azure pipeline variables'
inputs:
solution: scripts/version/ChangeVersion.proj
msbuildArgs: '/p:Sha1=$(Build.SourceVersion) /p:BranchName=$(Build.SourceBranchName) /p:BuildNumber=$(Build.BuildId) /p:BuildConfiguration=$(BuildConfiguration)'
vsVersion: $(vsVersion)
- script: '"${{ variables.MsBuildPath }}" /t:restore /p:RestoreLockedMode=true /p:RestoreConfigFile="analyzers\NuGet.Config" $(solution)'
displayName: "NuGet Restore"
- task: VSBuild@1
displayName: "Run .Net code analysis"
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArgs: '/p:DeployExtension=false /p:RunAnalyzers=true'
vsVersion: $(vsVersion)
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotnetCoverageNet48
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download coverage reports'
inputs:
artifact: DotnetCoverageNet6
targetPath: 'coverage'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotnetTestResultsNet48
targetPath: 'TestResults'
- task: DownloadPipelineArtifact@2
displayName: 'Download test results'
inputs:
artifact: DotnetTestResultsNet6
targetPath: 'TestResults'
- powershell: |
# Coverage is computed in another job and can have a different base path.
# We need to normalize content of the coverage files to the current job path.
# Values generated by the agent can look like this:
# `C:\ProgramData\vsts-agent\1\s`
# `C:\ProgramData\vsts-agent\2\s`
function Update-Coverage-BasePaths {
param (
$path
)
$localPath = (Get-Location).Path
$pattern = 'C:\\ProgramData\\vsts-agent\\\d+\\s'
(Get-Content -path $path -Raw) -replace $pattern,$localPath | Set-Content $path
}
Update-Coverage-BasePaths 'coverage\net48.xml'
Update-Coverage-BasePaths 'coverage\net6.0.xml'
displayName: Fix coverage paths
- task: SonarCloudAnalyze@1
displayName: 'Code Analysis - End'
- task: SonarCloudPublish@1
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'
- powershell: .\scripts\whitesource\WhiteSource-Scan.ps1
displayName: "WhiteSource scan"
condition: eq(variables.isReleaseBranch, 'True')
env:
WS_PRODUCTNAME: '$(WHITESOURCE_PRODUCTNAME)'
WS_APIKEY: '$(WHITESOURCE_APIKEY)'
BUILD_NUMBER: '$(Build.BuildId)'
GIT_SHA: '$(Build.SourceVersion)'
- job: runIntegrationTestsJob
displayName: '.NET ITs'
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download binaries to test'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- task: NuGetToolInstaller@1
displayName: "Install NuGet"
- task: PowerShell@2
displayName: 'Run ITs'
env:
SONAR_DOTNET_ENABLE_CONCURRENT_PROCESSING: true
inputs:
filePath: 'analyzers/its/regression-test.ps1'
workingDirectory: 'analyzers/its'
- job: runJavaBuild
displayName: 'Java build'
workspace:
clean: all
steps:
- task: DownloadPipelineArtifact@2
displayName: 'Download .Net binaries for Maven build'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- task: DownloadPipelineArtifact@2
displayName: 'Download rule descriptor binaries'
inputs:
artifact: RuleDescriptorBin
targetPath: analyzers\src\SonarAnalyzer.RuleDescriptorGenerator\bin
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- task: DownloadSecureFile@1
displayName: 'Download the sign key'
name: signKey
inputs:
secureFile: 'sign-key.asc'
- template: update-maven-version-steps.yml
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: Maven@3
displayName: 'Maven deploy'
env:
ARTIFACTORY_DEPLOY_USERNAME: $(ARTIFACTORY_DEPLOY_USERNAME)
ARTIFACTORY_DEPLOY_PASSWORD: $(ARTIFACTORY_DEPLOY_PASSWORD)
PGP_PASSPHRASE: $(PGP_PASSPHRASE)
GITHUB_BRANCH: $(Build.SourceBranchName)
GIT_SHA1: $(Build.SourceVersion)
inputs:
${{ if eq(variables.isReleaseBranch, 'True') }}:
goals: 'deploy -P release,sign'
${{ else }}:
goals: 'deploy -P release'
options: >-
$(commonMavenArguments)
--settings $(mavenSettings.secureFilePath)
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
- job: runJavaUnitTests
displayName: 'Java UTs'
dependsOn: runJavaBuild
workspace:
clean: all
steps:
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- template: update-maven-version-steps.yml
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: DownloadPipelineArtifact@2
displayName: 'Download .Net binaries for Maven build'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- task: DownloadPipelineArtifact@2
displayName: 'Download rule descriptor binaries'
inputs:
artifact: RuleDescriptorBin
targetPath: 'analyzers\src\SonarAnalyzer.RuleDescriptorGenerator\bin'
- task: SonarCloudPrepare@1
displayName: 'Prepare code analysis for Java plugin'
inputs:
SonarCloud: 'SonarCloud'
organization: 'sonarsource'
scannerMode: 'Other'
- task: Maven@3
displayName: 'Maven verify, UTs with SonarCloud'
inputs:
goals: 'verify'
options: -B --settings $(mavenSettings.secureFilePath) -Pcoverage -Dsonar.projectVersion=$(SONAR_PROJECT_VERSION)
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'UTs on Windows'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
sonarQubeRunAnalysis: true
sqMavenPluginVersionChoice: 'latest'
- task: SonarCloudPublish@1
displayName: 'Code Analysis - Publish QG'
inputs:
pollingTimeoutSec: '300'
- job: runJavaIntegrationTests
displayName: 'Java ITs'
dependsOn: runJavaBuild
workspace:
clean: all
strategy:
matrix:
CSharp:
testClasses: 'com.sonar.it.csharp.Tests'
Others:
testClasses: 'com.sonar.it.vbnet.Tests,com.sonar.it.shared.Tests'
steps:
- task: DownloadSecureFile@1
displayName: 'Download Maven settings'
name: mavenSettings
inputs:
secureFile: 'maven-settings.xml'
- template: update-maven-version-steps.yml
parameters:
mavenSettingsFilePath: $(mavenSettings.secureFilePath)
- task: DownloadPipelineArtifact@2
displayName: 'Download .Net binaries for Maven build'
inputs:
artifact: Binaries
targetPath: 'analyzers/packaging/binaries/'
- task: DownloadPipelineArtifact@2
displayName: 'Download rule descriptor binaries'
inputs:
artifact: RuleDescriptorBin
targetPath: 'analyzers\src\SonarAnalyzer.RuleDescriptorGenerator\bin'
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: Maven@3
displayName: 'Maven install'
env:
ARTIFACTORY_DEPLOY_USERNAME: $(ARTIFACTORY_DEPLOY_USERNAME)
ARTIFACTORY_DEPLOY_PASSWORD: $(ARTIFACTORY_DEPLOY_PASSWORD)
inputs:
goals: 'clean install'
options: >-
$(commonMavenArguments)
--settings $(mavenSettings.secureFilePath)
-DskipTests=true
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
- task: Maven@3
displayName: 'Maven ITs'
env:
ARTIFACTORY_API_KEY: $(ARTIFACTORY_API_KEY)
GITHUB_TOKEN: $(GITHUB_TOKEN)
inputs:
mavenPomFile: its/pom.xml
goals: 'verify'
options: -Dtest=$(testClasses) -B --settings $(mavenSettings.secureFilePath)
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
testRunTitle: 'ITs on Windows'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.11'
mavenOptions: $(MAVEN_OPTS)
- stage: promoteNugets
displayName: Promote NuGet on repox
dependsOn: qa
condition: succeeded()
jobs:
- job: promoteRepox
displayName: 'SonarAnalyzer.CFG.CSharp'
steps:
- template: set-azp-variables-steps.yml@pipelines-yaml-templates
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x'
- bash: pip3 install requests
- task: PythonScript@0
name: promoteRepox
inputs:
failOnStderr: true
scriptSource: 'inline'
script: |
import requests
import os
import sys
version = '$(SONAR_PROJECT_VERSION).$(Build.BuildId)'
isPr = '$(Build.Reason)' == 'PullRequest'
sourceRepo = os.environ['ARTIFACTORY_NUGET_REPO']
targetRepo = None
if isPr:
targetRepo = sourceRepo.replace('qa', 'dev')
else:
targetRepo = sourceRepo.replace('qa', 'public')
artifact = f'SonarAnalyzer.CFG.CSharp.{version}.nupkg'
print(f'Promoting nuget {artifact} from {sourceRepo} to {targetRepo}')
url = f'$(ARTIFACTORY_URL)/api/move/{sourceRepo}/{artifact}?to=/{targetRepo}/{artifact}'
headers = {'Content-Type': 'application/json'}
response = requests.post(url, headers=headers, auth=('$(ARTIFACTORY_API_USER)', '$(ARTIFACTORY_API_KEY)'))
fixedBranch = ''
if not isPr:
# Cannot use BUILD_SOURCEBRANCHNAME because of https://github.com/Microsoft/azure-pipelines-agent/issues/838
branch = os.environ['BUILD_SOURCEBRANCH']
refPrefix = "refs/heads/"
if branch.startswith(refPrefix):
fixedBranch = branch[len(refPrefix):]
print("##vso[task.setvariable variable=fixedBranch;isOutput=true]" + fixedBranch)
promoted = response.status_code == 200
if not promoted:
print('[!] [{0}] Server Error'.format(response.status_code), file=sys.stderr)
- job: nugetBurgrFailed
dependsOn: promoteRepox
pool: server
condition: failed()
steps:
- template: notify-burgr-steps.yml@pipelines-yaml-templates
parameters:
name: 'artifacts'
type: 'promotion'
status: 'failed'
fixedBranch: $(fixedBranch)
- job: nugetBurgrCanceled
dependsOn: promoteRepox
pool: server
condition: canceled()
steps:
- template: notify-burgr-steps.yml@pipelines-yaml-templates
parameters:
name: 'artifacts'
type: 'promotion'
status: 'canceled'
fixedBranch: $(fixedBranch)
- template: promote-stage.yml@pipelines-yaml-templates
parameters:
stageName: 'Artifacts:'
stageDependencies:
- promoteNugets