Changed: Moving conditional into sonarcloud inputs

This commit is contained in:
James Flynn 2021-03-02 16:11:34 +00:00
parent 0d06f34288
commit 0e7a37d0fc

View file

@ -8,14 +8,6 @@ pool:
# see: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml # see: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml
vmImage: ubuntu-20.04 vmImage: ubuntu-20.04
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)'
# Adding extra information into build name, to make it easier to identify builds. # Adding extra information into build name, to make it easier to identify builds.
# It can be called using '$(Build.BuildNumber)' # It can be called using '$(Build.BuildNumber)'
# see: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/run-number?view=azure-devops&tabs=yaml # see: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/run-number?view=azure-devops&tabs=yaml
@ -27,7 +19,7 @@ stages:
dependsOn: [] dependsOn: []
jobs: jobs:
- job: BuildTestDeploy - job: BuildTestDeploy
displayName: Build Test and Deploy spring-petclinic Java Web App displayName: Build Test and Package spring-petclinic
steps: steps:
# Azure DevOps extension for configuring SonarCloud properties # Azure DevOps extension for configuring SonarCloud properties
@ -42,8 +34,13 @@ stages:
scannerMode: 'Other' scannerMode: 'Other'
ProjectKey: 'james-flynn-ie_spring-petclinic' ProjectKey: 'james-flynn-ie_spring-petclinic'
ProjectName: 'spring-petclinic' ProjectName: 'spring-petclinic'
extraProperties: '$(SonarExtraProperties)' # 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') }}:
extraProperties: 'sonar.branch.name=$(Build.SourceBranchName)'
${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
extraProperties: 'sonar.pullrequest.key=$(System.PullRequest.PullRequestId) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch)'
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops
- task: Maven@3 - task: Maven@3
displayName: 'Maven Build, Test and Package' displayName: 'Maven Build, Test and Package'
@ -97,8 +94,13 @@ stages:
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs: jobs:
- job: DeployWebApp - job: DeployWebApp
displayName: Build Test and Deploy spring-petclinic Java Web App displayName: Deploy spring-petclinic Java Web App
steps: steps:
- task: DownloadPipelineArtifact@2
inputs:
artifact: 'jar-artifact'
path: $(System.DefaultWorkingDirectory)
# Deploy JAR into Azure Web App Service https://docs.microsoft.com/en-us/azure/app-service/overview # Deploy JAR into Azure Web App Service https://docs.microsoft.com/en-us/azure/app-service/overview
# Azure App Service offers a Web application hosting Platform-as-a-Service, offering: # Azure App Service offers a Web application hosting Platform-as-a-Service, offering:
# - Security # - Security