From 73bff7e33d9aa1492f3e8e159d1755dd91c7c4fe Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 20:38:48 +0000 Subject: [PATCH 01/28] Added: SonarCloud to pipeline --- azure-pipelines.yml | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index b75afdd9f..28f6f8a17 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -16,8 +16,17 @@ jobs: - job: BuildTestDeploy displayName: Build Test and Deploy spring-petclinic Java Web App steps: + + - task: SonarCloudPrepare@1 + displayName: 'Prepare SonarCloud scan' + inputs: + SonarCloud: 'sonarcloud-svc-connection' + organization: 'james-flynn-ie' + projectKey: 'spring-petclinic' + scannerMode: 'Other' + - task: Maven@3 - displayName: 'Maven Package' + displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' mavenOptions: '-Xmx3072m' @@ -29,6 +38,14 @@ jobs: testResultsFiles: '**/TEST-*.xml' goals: 'package' + - task: SonarCloudAnalyze@1 + displayName: 'Run SonarCloud Code Analysis' + + - task: SonarCloudPublish@1 + displayName: 'Publish Quality Gate Result on SonarCloud' + inputs: + pollingTimeoutSec: '300' + - task: CopyFiles@2 displayName: 'Copy Files to artifact staging directory' inputs: From 1b9bbdf7a49fa02faf5c9745d67a36b4beb6684c Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 20:48:02 +0000 Subject: [PATCH 02/28] Removed: sonarcloud analyse, enables with Maven task instead --- azure-pipelines.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 28f6f8a17..cb4021ed7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,18 +29,18 @@ jobs: displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' - mavenOptions: '-Xmx3072m' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + testRunTitle: '$(Build.BuildNumber)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' - jdkArchitectureOption: 'x64' - publishJUnitResults: true - testRunTitle: '$(Build.BuildNumber)' - testResultsFiles: '**/TEST-*.xml' - goals: 'package' + mavenVersionOption: 'Default' + mavenOptions: '-Xmx3072m' + mavenAuthenticateFeed: false + effectivePomSkip: false + sonarQubeRunAnalysis: true + sqMavenPluginVersionChoice: 'latest' - - task: SonarCloudAnalyze@1 - displayName: 'Run SonarCloud Code Analysis' - - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' inputs: From 6955e07e2461ed61d2811f774a641b83b3d96c3c Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 20:57:08 +0000 Subject: [PATCH 03/28] Fixed: SonarCloud Org name --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cb4021ed7..918b6f6d1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,7 +21,7 @@ jobs: displayName: 'Prepare SonarCloud scan' inputs: SonarCloud: 'sonarcloud-svc-connection' - organization: 'james-flynn-ie' + organization: 'James Flynn' projectKey: 'spring-petclinic' scannerMode: 'Other' From 13e3677c778d5c78d4ecfa727959784ddbb2053e Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 21:13:49 +0000 Subject: [PATCH 04/28] Added: Separate run sonarcloud analysis step --- azure-pipelines.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 918b6f6d1..67c889b08 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -18,12 +18,13 @@ jobs: steps: - task: SonarCloudPrepare@1 - displayName: 'Prepare SonarCloud scan' + displayName: 'Prepare SonarCloud Code Analysis Scan' inputs: SonarCloud: 'sonarcloud-svc-connection' - organization: 'James Flynn' - projectKey: 'spring-petclinic' scannerMode: 'Other' + organization: 'james-flynn-ie' + projectKey: 'spring-petclinic' + - task: Maven@3 displayName: 'Maven Build, Test and Package' @@ -38,8 +39,11 @@ jobs: mavenOptions: '-Xmx3072m' mavenAuthenticateFeed: false effectivePomSkip: false - sonarQubeRunAnalysis: true - sqMavenPluginVersionChoice: 'latest' + # Run SonarCloud analysis as a separate step + sqAnalysisEnabled: true + + - task: SonarCloudAnalyze@1 + displayName: 'Run SonarCloud Code Analysis Scan' - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' From c60a906e65db12b971178488b5e94f1d0e6e2e4e Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 21:26:17 +0000 Subject: [PATCH 05/28] Added: Sonar extra properties --- azure-pipelines.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 67c889b08..673027765 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,7 +24,11 @@ jobs: scannerMode: 'Other' organization: 'james-flynn-ie' projectKey: 'spring-petclinic' - + extraProperties: + sonar.branch.name=$(Build.SourceBranchName) + sonar.language=java + sonar.sources=src/main/java/org/springframework/samples/petclinic/* + sonar.sourceEncoding=UTF-8 - task: Maven@3 displayName: 'Maven Build, Test and Package' @@ -39,11 +43,8 @@ jobs: mavenOptions: '-Xmx3072m' mavenAuthenticateFeed: false effectivePomSkip: false - # Run SonarCloud analysis as a separate step - sqAnalysisEnabled: true - - - task: SonarCloudAnalyze@1 - displayName: 'Run SonarCloud Code Analysis Scan' + sonarQubeRunAnalysis: true + sqMavenPluginVersionChoice: 'latest' - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' From a156027e036485437c53caf251c3cf430c2fdc9d Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 21:37:09 +0000 Subject: [PATCH 06/28] Added: project key to sonar extra properties --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 673027765..256d2ff89 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -23,10 +23,10 @@ jobs: SonarCloud: 'sonarcloud-svc-connection' scannerMode: 'Other' organization: 'james-flynn-ie' - projectKey: 'spring-petclinic' extraProperties: sonar.branch.name=$(Build.SourceBranchName) sonar.language=java + sonar.projectKey=spring-petclinic sonar.sources=src/main/java/org/springframework/samples/petclinic/* sonar.sourceEncoding=UTF-8 From dce75693d3a7bfb398a42d066e5e8d01840bdc00 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 21:53:41 +0000 Subject: [PATCH 07/28] Changed: ScannerMode to CLI --- azure-pipelines.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 256d2ff89..664b9179d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,14 +21,14 @@ jobs: displayName: 'Prepare SonarCloud Code Analysis Scan' inputs: SonarCloud: 'sonarcloud-svc-connection' - scannerMode: 'Other' + scannerMode: 'CLI' + configMode: 'manual' + cliProjectKey: 'spring-petclinic' organization: 'james-flynn-ie' - extraProperties: + cliSources: 'src/main/java/org/springframework/samples/petclinic/' + extraProperties: sonar.branch.name=$(Build.SourceBranchName) sonar.language=java - sonar.projectKey=spring-petclinic - sonar.sources=src/main/java/org/springframework/samples/petclinic/* - sonar.sourceEncoding=UTF-8 - task: Maven@3 displayName: 'Maven Build, Test and Package' @@ -43,8 +43,9 @@ jobs: mavenOptions: '-Xmx3072m' mavenAuthenticateFeed: false effectivePomSkip: false - sonarQubeRunAnalysis: true - sqMavenPluginVersionChoice: 'latest' + + - task: SonarCloudAnalyze@1 + displayName: 'Run Sonarcloud Code Analysis' - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' From 41dace5c50889923aead6ad9d2cf47294c8b7cf5 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 21:58:15 +0000 Subject: [PATCH 08/28] Fixed: Maven task auto-updated by Azure DevOps --- azure-pipelines.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 664b9179d..91d97c5e5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -34,15 +34,14 @@ jobs: displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' - publishJUnitResults: true - testResultsFiles: '**/TEST-*.xml' - testRunTitle: '$(Build.BuildNumber)' + mavenOptions: '-Xmx3072m' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' - mavenVersionOption: 'Default' - mavenOptions: '-Xmx3072m' - mavenAuthenticateFeed: false - effectivePomSkip: false + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testRunTitle: '$(Build.BuildNumber)' + testResultsFiles: '**/TEST-*.xml' + goals: 'package' - task: SonarCloudAnalyze@1 displayName: 'Run Sonarcloud Code Analysis' From b65e7b621047e14c676df083ca1a041d7cc145cf Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 22:02:51 +0000 Subject: [PATCH 09/28] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 91d97c5e5..aeeb7a670 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,7 +25,7 @@ jobs: configMode: 'manual' cliProjectKey: 'spring-petclinic' organization: 'james-flynn-ie' - cliSources: 'src/main/java/org/springframework/samples/petclinic/' + cliSources: '.' extraProperties: sonar.branch.name=$(Build.SourceBranchName) sonar.language=java From 713fb2a8c0bee71f7b17f9239b355bcb6ebc6b52 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 22:13:36 +0000 Subject: [PATCH 10/28] Changed: sonarcloud prep inputs updated for CLI mode --- azure-pipelines.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index aeeb7a670..33446d478 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,14 +21,13 @@ jobs: displayName: 'Prepare SonarCloud Code Analysis Scan' inputs: SonarCloud: 'sonarcloud-svc-connection' + organization: 'james-flynn-ie' scannerMode: 'CLI' configMode: 'manual' cliProjectKey: 'spring-petclinic' - organization: 'james-flynn-ie' + cliProjectName: 'spring-petclinic' cliSources: '.' - extraProperties: - sonar.branch.name=$(Build.SourceBranchName) - sonar.language=java + extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java' - task: Maven@3 displayName: 'Maven Build, Test and Package' From eb6141f03e6a2a521b906f6db346226c548825f5 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 22:46:32 +0000 Subject: [PATCH 11/28] Added: sonar.projectKey to extraproperties --- azure-pipelines.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 33446d478..faec7ea99 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,10 +24,9 @@ jobs: organization: 'james-flynn-ie' scannerMode: 'CLI' configMode: 'manual' - cliProjectKey: 'spring-petclinic' cliProjectName: 'spring-petclinic' cliSources: '.' - extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java' + extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic' - task: Maven@3 displayName: 'Maven Build, Test and Package' From b9a2298eec44a20cc1d001fb969ea60af51be986 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 22:47:45 +0000 Subject: [PATCH 12/28] Added: CliProjectKey to sonarcloud task --- azure-pipelines.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index faec7ea99..c488d4ead 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -24,6 +24,7 @@ jobs: organization: 'james-flynn-ie' scannerMode: 'CLI' configMode: 'manual' + cliProjectKey: 'james-flynn-ie_spring-petclinic' cliProjectName: 'spring-petclinic' cliSources: '.' extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic' From 046bc13b744b90ef52ba7cd6b82b6a95713851e3 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 22:56:13 +0000 Subject: [PATCH 13/28] Changed: Using Mvn task sonar scan --- azure-pipelines.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c488d4ead..32302af48 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,28 +22,25 @@ jobs: inputs: SonarCloud: 'sonarcloud-svc-connection' organization: 'james-flynn-ie' - scannerMode: 'CLI' + scannerMode: 'Other' configMode: 'manual' - cliProjectKey: 'james-flynn-ie_spring-petclinic' - cliProjectName: 'spring-petclinic' - cliSources: '.' - extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic' + projectKey: 'james-flynn-ie_spring-petclinic' + projectName: 'spring-petclinic' + extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java' - task: Maven@3 displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' - mavenOptions: '-Xmx3072m' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + testRunTitle: '$(Build.BuildNumber)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' - jdkArchitectureOption: 'x64' - publishJUnitResults: true - testRunTitle: '$(Build.BuildNumber)' - testResultsFiles: '**/TEST-*.xml' - goals: 'package' - - - task: SonarCloudAnalyze@1 - displayName: 'Run Sonarcloud Code Analysis' + mavenVersionOption: 'Default' + mavenOptions: '-Xmx3072m' + sonarQubeRunAnalysis: true + sqMavenPluginVersionChoice: 'latest' - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' From 13c4f99f3c08c3463a65d76de05f912036a50071 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Mon, 1 Mar 2021 23:05:52 +0000 Subject: [PATCH 14/28] Changed: Reverted changes back to CLI --- azure-pipelines.yml | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 32302af48..c488d4ead 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,25 +22,28 @@ jobs: inputs: SonarCloud: 'sonarcloud-svc-connection' organization: 'james-flynn-ie' - scannerMode: 'Other' + scannerMode: 'CLI' configMode: 'manual' - projectKey: 'james-flynn-ie_spring-petclinic' - projectName: 'spring-petclinic' - extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java' + cliProjectKey: 'james-flynn-ie_spring-petclinic' + cliProjectName: 'spring-petclinic' + cliSources: '.' + extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic' - task: Maven@3 displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' - publishJUnitResults: true - testResultsFiles: '**/TEST-*.xml' - testRunTitle: '$(Build.BuildNumber)' + mavenOptions: '-Xmx3072m' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' - mavenVersionOption: 'Default' - mavenOptions: '-Xmx3072m' - sonarQubeRunAnalysis: true - sqMavenPluginVersionChoice: 'latest' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testRunTitle: '$(Build.BuildNumber)' + testResultsFiles: '**/TEST-*.xml' + goals: 'package' + + - task: SonarCloudAnalyze@1 + displayName: 'Run Sonarcloud Code Analysis' - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' From cb962d7e55caf6daccffc166c658a90ae25cbba8 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 14:19:32 +0000 Subject: [PATCH 15/28] Added: Mvn sonar clean install --- azure-pipelines.yml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c488d4ead..db7800585 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -22,25 +22,30 @@ jobs: inputs: SonarCloud: 'sonarcloud-svc-connection' organization: 'james-flynn-ie' - scannerMode: 'CLI' - configMode: 'manual' - cliProjectKey: 'james-flynn-ie_spring-petclinic' - cliProjectName: 'spring-petclinic' - cliSources: '.' - extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic' + scannerMode: 'Other' + ProjectKey: 'james-flynn-ie_spring-petclinic' + ProjectName: 'spring-petclinic' + extraProperties: | + sonar.branch.name=$(Build.SourceBranchName) + sonar.language=java + sonar.projectKey=james-flynn-ie_spring-petclinic - task: Maven@3 displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' - mavenOptions: '-Xmx3072m' + goals: 'clean install sonar:sonar package' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + testRunTitle: '$(Build.BuildNumber)' javaHomeOption: 'JDKVersion' jdkVersionOption: '1.11' - jdkArchitectureOption: 'x64' - publishJUnitResults: true - testRunTitle: '$(Build.BuildNumber)' - testResultsFiles: '**/TEST-*.xml' - goals: 'package' + mavenVersionOption: 'Default' + mavenOptions: '-Xmx3072m' + mavenAuthenticateFeed: false + effectivePomSkip: false + sonarQubeRunAnalysis: true + sqMavenPluginVersionChoice: 'latest' - task: SonarCloudAnalyze@1 displayName: 'Run Sonarcloud Code Analysis' From 1eb273dcecbeed0dabd99967b818c2549f351492 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 14:55:15 +0000 Subject: [PATCH 16/28] Added: improved commenting and references --- azure-pipelines.yml | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index db7800585..90b7dbad3 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -5,11 +5,12 @@ pool: # - The build VM is deployed by Microsoft, reducing maintenance. # - Tools within the VM Image are always up to date. # - Fresh build environment for every run (to reduce contamination from other runs). - # 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 # Adding extra information into build name, to make it easier to identify builds. # 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 name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r) jobs: @@ -17,23 +18,31 @@ jobs: displayName: Build Test and Deploy spring-petclinic Java Web App steps: + # Azure DevOps extension for configuring SonarCloud properties + # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud - task: SonarCloudPrepare@1 displayName: 'Prepare SonarCloud Code Analysis Scan' inputs: + # Azure DevOps Service Connection is used in place of secureSonar Token value within repo. + # For configuring, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml SonarCloud: 'sonarcloud-svc-connection' organization: 'james-flynn-ie' scannerMode: 'Other' ProjectKey: 'james-flynn-ie_spring-petclinic' ProjectName: 'spring-petclinic' extraProperties: | + # see: https://sonarcloud.io/documentation/analysis/analysis-parameters/ sonar.branch.name=$(Build.SourceBranchName) sonar.language=java sonar.projectKey=james-flynn-ie_spring-petclinic + # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3 displayName: 'Maven Build, Test and Package' inputs: mavenPomFile: 'pom.xml' + # 'clean install sonar:sonar' is required to run the Sonarcloud scan ('package' creates the JAR). + # see: https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-in-azure.html goals: 'clean install sonar:sonar package' publishJUnitResults: true testResultsFiles: '**/TEST-*.xml' @@ -47,14 +56,14 @@ jobs: sonarQubeRunAnalysis: true sqMavenPluginVersionChoice: 'latest' - - task: SonarCloudAnalyze@1 - displayName: 'Run Sonarcloud Code Analysis' - + # Adds results and link to sonarcloud.io reports under 'Extensions' tab on pipeline run report. + # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud - task: SonarCloudPublish@1 displayName: 'Publish Quality Gate Result on SonarCloud' inputs: pollingTimeoutSec: '300' + # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml - task: CopyFiles@2 displayName: 'Copy Files to artifact staging directory' inputs: @@ -63,7 +72,8 @@ jobs: TargetFolder: $(Build.ArtifactStagingDirectory) preserveTimestamp: true - # Publish build artifacts to Azure Pipelines. Extension uses Robocopy "under the hood." + # Publish build artifacts to Azure Pipelines (Continuous Delivery). + # Build artifacts are retained and can be downloaded for local use, or used in other stages or pipeline runs for deployments. # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops - task: PublishBuildArtifacts@1 inputs: @@ -73,13 +83,20 @@ jobs: parallel: true # Increased speed through multi-threaded copying. parallelCount: 8 # Dependent upon CPU capabilities. + # 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: + # - Security + # - Load balancing + # - High Availability and autoscaling (based on policies) + # For pipeline configuration, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app?view=azure-devops - task: AzureWebApp@1 displayName: Deploy spring-petclinic to Azure Web App service inputs: + # For configuring Service Connection, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml azureSubscription: 'azure-svc-connection' appType: webAppLinux appName: 'james-pet-clinic' package: '$(System.DefaultWorkingDirectory)/**/*.jar' # Only deploy web app from main branch (for release purposes) condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) - \ No newline at end of file +... From 42fb06b86d414cb3d3763a0ca908a5a8f03d911b Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:05:12 +0000 Subject: [PATCH 17/28] Removed: extra properties from sonarcloud prep --- azure-pipelines.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 90b7dbad3..56ba6c5dc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,11 +30,6 @@ jobs: scannerMode: 'Other' ProjectKey: 'james-flynn-ie_spring-petclinic' ProjectName: 'spring-petclinic' - extraProperties: | - # see: https://sonarcloud.io/documentation/analysis/analysis-parameters/ - sonar.branch.name=$(Build.SourceBranchName) - sonar.language=java - sonar.projectKey=james-flynn-ie_spring-petclinic # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3 From 29720eb4884aebfa507a01b8f230582e88620e6b Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:31:29 +0000 Subject: [PATCH 18/28] 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 From 631e79fdf8a4951021b387928a9272bab94c8599 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:38:51 +0000 Subject: [PATCH 19/28] Fixed: conditional block syntax --- azure-pipelines.yml | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bdf0bed64..958d2ceb9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -13,16 +13,15 @@ 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 + 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)' displayName: Build Test and Deploy spring-petclinic Java Web App steps: From fd95717cfc547f84fd6a7ecea98df0f71fdda25c Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:47:04 +0000 Subject: [PATCH 20/28] Added: echo of variable for debugging --- azure-pipelines.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 958d2ceb9..ab3084d9a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,6 +8,14 @@ pool: # see: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml 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. # 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 @@ -15,15 +23,11 @@ name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r) jobs: - job: BuildTestDeploy - 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)' displayName: Build Test and Deploy spring-petclinic Java Web App steps: + - task: PowerShell@1 + inputs: + inlineScript: echo $(SonarExtraProperties) # Azure DevOps extension for configuring SonarCloud properties # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud From 817287ce04dd085b3acc0dcaf71b2a23e18df929 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:50:10 +0000 Subject: [PATCH 21/28] Added: echo of variable for debugging --- azure-pipelines.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index ab3084d9a..6fe67136f 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,9 +25,7 @@ jobs: - job: BuildTestDeploy displayName: Build Test and Deploy spring-petclinic Java Web App steps: - - task: PowerShell@1 - inputs: - inlineScript: echo $(SonarExtraProperties) + - script: echo $(SonarExtraProperties) # Azure DevOps extension for configuring SonarCloud properties # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud From 5ef90348d406abe947c89e34f4c94eff5aa25b4b Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 15:58:26 +0000 Subject: [PATCH 22/28] Added: CI and CD stages --- azure-pipelines.yml | 171 +++++++++++++++++++++++--------------------- 1 file changed, 91 insertions(+), 80 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6fe67136f..acf4e52c4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -21,87 +21,98 @@ variables: # 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) -jobs: - - job: BuildTestDeploy - displayName: Build Test and Deploy spring-petclinic Java Web App - steps: - - script: echo $(SonarExtraProperties) +stages: + - stage: CI + displayName: 'Continuous Integration' + dependsOn: [] + jobs: + - job: BuildTestDeploy + displayName: Build Test and Deploy spring-petclinic Java Web App + steps: - # Azure DevOps extension for configuring SonarCloud properties - # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud - - task: SonarCloudPrepare@1 - displayName: 'Prepare SonarCloud Code Analysis Scan' - inputs: - # Azure DevOps Service Connection is used in place of secureSonar Token value within repo. - # For configuring, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml - SonarCloud: 'sonarcloud-svc-connection' - organization: 'james-flynn-ie' - scannerMode: 'Other' - ProjectKey: 'james-flynn-ie_spring-petclinic' - ProjectName: 'spring-petclinic' - extraProperties: $(SonarExtraProperties) + # Azure DevOps extension for configuring SonarCloud properties + # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud + - task: SonarCloudPrepare@1 + displayName: 'Prepare SonarCloud Code Analysis Scan' + inputs: + # Azure DevOps Service Connection is used in place of secureSonar Token value within repo. + # For configuring, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml + SonarCloud: 'sonarcloud-svc-connection' + organization: 'james-flynn-ie' + 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 + displayName: 'Maven Build, Test and Package' + inputs: + mavenPomFile: 'pom.xml' + # 'clean install sonar:sonar' is required to run the Sonarcloud scan ('package' creates the JAR). + # see: https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-in-azure.html + goals: 'clean install sonar:sonar package' + publishJUnitResults: true + testResultsFiles: '**/TEST-*.xml' + testRunTitle: '$(Build.BuildNumber)' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.11' + mavenVersionOption: 'Default' + mavenOptions: '-Xmx3072m' + mavenAuthenticateFeed: false + effectivePomSkip: false + sonarQubeRunAnalysis: true + sqMavenPluginVersionChoice: 'latest' + + # Adds results and link to sonarcloud.io reports under 'Extensions' tab on pipeline run report. + # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud + - task: SonarCloudPublish@1 + displayName: 'Publish Quality Gate Result on SonarCloud' + inputs: + pollingTimeoutSec: '300' - # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - - task: Maven@3 - displayName: 'Maven Build, Test and Package' - inputs: - mavenPomFile: 'pom.xml' - # 'clean install sonar:sonar' is required to run the Sonarcloud scan ('package' creates the JAR). - # see: https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-in-azure.html - goals: 'clean install sonar:sonar package' - publishJUnitResults: true - testResultsFiles: '**/TEST-*.xml' - testRunTitle: '$(Build.BuildNumber)' - javaHomeOption: 'JDKVersion' - jdkVersionOption: '1.11' - mavenVersionOption: 'Default' - mavenOptions: '-Xmx3072m' - mavenAuthenticateFeed: false - effectivePomSkip: false - sonarQubeRunAnalysis: true - sqMavenPluginVersionChoice: 'latest' + # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml + - task: CopyFiles@2 + displayName: 'Copy Files to artifact staging directory' + inputs: + SourceFolder: '$(System.DefaultWorkingDirectory)' + Contents: '**/target/*.?(war|jar)' + TargetFolder: $(Build.ArtifactStagingDirectory) + preserveTimestamp: true + + # Publish build artifacts to Azure Pipelines (Continuous Delivery). + # Build artifacts are retained and can be downloaded for local use, or used in other stages or pipeline runs for deployments. + # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops + - task: PublishBuildArtifacts@1 + inputs: + pathToPublish: '$(Build.ArtifactStagingDirectory)/target' + artifactName: 'jar-artifact' + publishLocation: 'Container' # Publishes inside Azure Pipelines artifact folder. + parallel: true # Increased speed through multi-threaded copying. + parallelCount: 8 # Dependent upon CPU capabilities. - # Adds results and link to sonarcloud.io reports under 'Extensions' tab on pipeline run report. - # see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud - - task: SonarCloudPublish@1 - displayName: 'Publish Quality Gate Result on SonarCloud' - inputs: - pollingTimeoutSec: '300' - - # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml - - task: CopyFiles@2 - displayName: 'Copy Files to artifact staging directory' - inputs: - SourceFolder: '$(System.DefaultWorkingDirectory)' - Contents: '**/target/*.?(war|jar)' - TargetFolder: $(Build.ArtifactStagingDirectory) - preserveTimestamp: true - - # Publish build artifacts to Azure Pipelines (Continuous Delivery). - # Build artifacts are retained and can be downloaded for local use, or used in other stages or pipeline runs for deployments. - # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops - - task: PublishBuildArtifacts@1 - inputs: - pathToPublish: '$(Build.ArtifactStagingDirectory)/target' - artifactName: 'jar-artifact' - publishLocation: 'Container' # Publishes inside Azure Pipelines artifact folder. - parallel: true # Increased speed through multi-threaded copying. - parallelCount: 8 # Dependent upon CPU capabilities. - - # 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: - # - Security - # - Load balancing - # - High Availability and autoscaling (based on policies) - # For pipeline configuration, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app?view=azure-devops - - task: AzureWebApp@1 - displayName: Deploy spring-petclinic to Azure Web App service - inputs: - # For configuring Service Connection, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml - azureSubscription: 'azure-svc-connection' - appType: webAppLinux - appName: 'james-pet-clinic' - package: '$(System.DefaultWorkingDirectory)/**/*.jar' - # Only deploy web app from main branch (for release purposes) - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) + - stage: CI + displayName: 'Continuous Deployment' + dependsOn: [CI] + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) + jobs: + - job: DeployWebApp + displayName: Build Test and Deploy spring-petclinic Java Web App + steps: + # 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: + # - Security + # - Load balancing + # - High Availability and autoscaling (based on policies) + # For pipeline configuration, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app?view=azure-devops + - task: AzureWebApp@1 + displayName: Deploy spring-petclinic to Azure Web App service + inputs: + # For configuring Service Connection, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml + azureSubscription: 'azure-svc-connection' + appType: webAppLinux + appName: 'james-pet-clinic' + package: '$(System.DefaultWorkingDirectory)/**/*.jar' + # Only deploy web app from main branch (for release purposes) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) ... From 0d06f34288b8007deee922daedb28a1933cb9ab4 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:00:12 +0000 Subject: [PATCH 23/28] Changed: CD stage name --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index acf4e52c4..16da703e7 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -91,7 +91,7 @@ stages: parallel: true # Increased speed through multi-threaded copying. parallelCount: 8 # Dependent upon CPU capabilities. - - stage: CI + - stage: CD displayName: 'Continuous Deployment' dependsOn: [CI] condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) From 0e7a37d0fce44f6d8c0798b0d562c3a97b5f2ce2 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:11:34 +0000 Subject: [PATCH 24/28] Changed: Moving conditional into sonarcloud inputs --- azure-pipelines.yml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 16da703e7..f4ad71691 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -8,14 +8,6 @@ pool: # see: https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml 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. # 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 @@ -27,7 +19,7 @@ stages: dependsOn: [] jobs: - job: BuildTestDeploy - displayName: Build Test and Deploy spring-petclinic Java Web App + displayName: Build Test and Package spring-petclinic steps: # Azure DevOps extension for configuring SonarCloud properties @@ -42,8 +34,13 @@ stages: scannerMode: 'Other' ProjectKey: 'james-flynn-ie_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 - task: Maven@3 displayName: 'Maven Build, Test and Package' @@ -97,8 +94,13 @@ stages: condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) jobs: - job: DeployWebApp - displayName: Build Test and Deploy spring-petclinic Java Web App + displayName: Deploy spring-petclinic Java Web App 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 # Azure App Service offers a Web application hosting Platform-as-a-Service, offering: # - Security From 744e9e21bebebfbd49442a8eef0d30942f806366 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:20:19 +0000 Subject: [PATCH 25/28] Changed: Moving conditional into sonarcloud inputs --- azure-pipelines.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f4ad71691..82eeafe65 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,8 +14,8 @@ pool: name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r) stages: - - stage: CI - displayName: 'Continuous Integration' + - stage: ContinuousIntegration+Delivery + displayName: 'Continuous Integration and Delivery' dependsOn: [] jobs: - job: BuildTestDeploy @@ -37,9 +37,9 @@ stages: # 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)' + extraProperties: 'sonar.branch.name=$(Build.SourceBranchName) sonar.projectKey=james-flynn-ie_spring-petclinic' ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - extraProperties: 'sonar.pullrequest.key=$(System.PullRequest.PullRequestId) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch)' + extraProperties: 'sonar.pullrequest.key=$(System.PullRequest.pullRequestNumber) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch) sonar.projectKey=james-flynn-ie_spring-petclinic' # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3 @@ -88,9 +88,9 @@ stages: parallel: true # Increased speed through multi-threaded copying. parallelCount: 8 # Dependent upon CPU capabilities. - - stage: CD + - stage: ContinuousDeployment displayName: 'Continuous Deployment' - dependsOn: [CI] + dependsOn: [ContinuousIntegration+Delivery] condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) jobs: - job: DeployWebApp @@ -116,5 +116,4 @@ stages: appName: 'james-pet-clinic' package: '$(System.DefaultWorkingDirectory)/**/*.jar' # Only deploy web app from main branch (for release purposes) - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) ... From fc95a32d05f0adb12c138c0a7f2ffde7e0eae843 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:22:10 +0000 Subject: [PATCH 26/28] Fixed: stage names --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 82eeafe65..41a6ee052 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,7 +14,7 @@ pool: name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r) stages: - - stage: ContinuousIntegration+Delivery + - stage: CI_CDelivery displayName: 'Continuous Integration and Delivery' dependsOn: [] jobs: @@ -88,9 +88,9 @@ stages: parallel: true # Increased speed through multi-threaded copying. parallelCount: 8 # Dependent upon CPU capabilities. - - stage: ContinuousDeployment + - stage: CDeployment displayName: 'Continuous Deployment' - dependsOn: [ContinuousIntegration+Delivery] + dependsOn: [CI_CDelivery] condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main')) jobs: - job: DeployWebApp From 8f0d18a9c73c3ec6d43b75b2b8f56952b1c4fb7b Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:30:47 +0000 Subject: [PATCH 27/28] Changed: extra properties structure --- azure-pipelines.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 41a6ee052..7ddc629f5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -37,9 +37,16 @@ stages: # 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) sonar.projectKey=james-flynn-ie_spring-petclinic' + extraProperties: | + sonar.branch.name=$(Build.SourceBranchName) + sonar.language=java + sonar.projectKey=james-flynn-ie_spring-petclinic' ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - extraProperties: 'sonar.pullrequest.key=$(System.PullRequest.pullRequestNumber) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch) sonar.projectKey=james-flynn-ie_spring-petclinic' + extraProperties: | + sonar.pullrequest.key=$(System.PullRequest.pullRequestNumber) + sonar.pullrequest.branch=$(Build.SourceBranchName) + sonar.pullrequest.base=$(System.PullRequest.TargetBranch) + sonar.projectKey=james-flynn-ie_spring-petclinic' # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3 From b69de88e8e8ff658ca11b729279642df71578527 Mon Sep 17 00:00:00 2001 From: James Flynn Date: Tue, 2 Mar 2021 16:38:31 +0000 Subject: [PATCH 28/28] Fixed: removed quote from extra properties --- azure-pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 7ddc629f5..bfd9f5ec2 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -40,13 +40,13 @@ stages: extraProperties: | sonar.branch.name=$(Build.SourceBranchName) sonar.language=java - sonar.projectKey=james-flynn-ie_spring-petclinic' + sonar.projectKey=james-flynn-ie_spring-petclinic ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: extraProperties: | sonar.pullrequest.key=$(System.PullRequest.pullRequestNumber) sonar.pullrequest.branch=$(Build.SourceBranchName) sonar.pullrequest.base=$(System.PullRequest.TargetBranch) - sonar.projectKey=james-flynn-ie_spring-petclinic' + sonar.projectKey=james-flynn-ie_spring-petclinic # https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/maven?view=azure-devops - task: Maven@3