From 29720eb4884aebfa507a01b8f230582e88620e6b Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:31:29 +0000 Subject: [PATCH] Added: Sonarcloud PR extra params --- azure-pipelines.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 56ba6c5dc..bdf0bed64 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,6 +13,14 @@ pool: # see: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/run-number?view=azure-devops&tabs=yaml name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r) +variables: + # Sonar scanner does not allow branch name to be set for Pull Requests (PRs), but returns an error if not specified for CI builds. + # This conditional block only passes the branch name if build is not for a PR, otherwise it passes the Sonar PR params: + if {{ $[ne(variables['Build.Reason'], 'PullRequest')] }}: + SonarExtraProperties: 'sonar.branch.name=$(Build.SourceBranchName)' + if {{ $[eq(variables['Build.Reason'], 'PullRequest')] }}: + SonarExtraProperties: 'sonar.pullrequest.key=$(System.PullRequest.PullRequestId) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch)' + jobs: - job: BuildTestDeploy displayName: Build Test and Deploy spring-petclinic Java Web App @@ -30,6 +38,7 @@ jobs: scannerMode: 'Other' ProjectKey: 'james-flynn-ie_spring-petclinic' ProjectName: 'spring-petclinic' + extraProperties: $(SonarExtraProperties) # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3