mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Added: CI and CD stages
This commit is contained in:
parent
817287ce04
commit
5ef90348d4
1 changed files with 91 additions and 80 deletions
|
@ -21,87 +21,98 @@ variables:
|
||||||
# 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
|
||||||
name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r)
|
name: $(Build.DefinitionName).$(SourceBranchName).$(Date:yyyyMMdd)$(Rev:.r)
|
||||||
|
|
||||||
jobs:
|
stages:
|
||||||
- job: BuildTestDeploy
|
- stage: CI
|
||||||
displayName: Build Test and Deploy spring-petclinic Java Web App
|
displayName: 'Continuous Integration'
|
||||||
steps:
|
dependsOn: []
|
||||||
- script: echo $(SonarExtraProperties)
|
jobs:
|
||||||
|
- job: BuildTestDeploy
|
||||||
|
displayName: Build Test and Deploy spring-petclinic Java Web App
|
||||||
|
steps:
|
||||||
|
|
||||||
# Azure DevOps extension for configuring SonarCloud properties
|
# Azure DevOps extension for configuring SonarCloud properties
|
||||||
# see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud
|
# see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud
|
||||||
- task: SonarCloudPrepare@1
|
- task: SonarCloudPrepare@1
|
||||||
displayName: 'Prepare SonarCloud Code Analysis Scan'
|
displayName: 'Prepare SonarCloud Code Analysis Scan'
|
||||||
inputs:
|
inputs:
|
||||||
# Azure DevOps Service Connection is used in place of secureSonar Token value within repo.
|
# 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
|
# For configuring, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml
|
||||||
SonarCloud: 'sonarcloud-svc-connection'
|
SonarCloud: 'sonarcloud-svc-connection'
|
||||||
organization: 'james-flynn-ie'
|
organization: 'james-flynn-ie'
|
||||||
scannerMode: 'Other'
|
scannerMode: 'Other'
|
||||||
ProjectKey: 'james-flynn-ie_spring-petclinic'
|
ProjectKey: 'james-flynn-ie_spring-petclinic'
|
||||||
ProjectName: 'spring-petclinic'
|
ProjectName: 'spring-petclinic'
|
||||||
extraProperties: $(SonarExtraProperties)
|
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
|
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml
|
||||||
- task: Maven@3
|
- task: CopyFiles@2
|
||||||
displayName: 'Maven Build, Test and Package'
|
displayName: 'Copy Files to artifact staging directory'
|
||||||
inputs:
|
inputs:
|
||||||
mavenPomFile: 'pom.xml'
|
SourceFolder: '$(System.DefaultWorkingDirectory)'
|
||||||
# 'clean install sonar:sonar' is required to run the Sonarcloud scan ('package' creates the JAR).
|
Contents: '**/target/*.?(war|jar)'
|
||||||
# see: https://www.coachdevops.com/2020/04/how-to-integrate-sonarqube-in-azure.html
|
TargetFolder: $(Build.ArtifactStagingDirectory)
|
||||||
goals: 'clean install sonar:sonar package'
|
preserveTimestamp: true
|
||||||
publishJUnitResults: true
|
|
||||||
testResultsFiles: '**/TEST-*.xml'
|
# Publish build artifacts to Azure Pipelines (Continuous Delivery).
|
||||||
testRunTitle: '$(Build.BuildNumber)'
|
# Build artifacts are retained and can be downloaded for local use, or used in other stages or pipeline runs for deployments.
|
||||||
javaHomeOption: 'JDKVersion'
|
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops
|
||||||
jdkVersionOption: '1.11'
|
- task: PublishBuildArtifacts@1
|
||||||
mavenVersionOption: 'Default'
|
inputs:
|
||||||
mavenOptions: '-Xmx3072m'
|
pathToPublish: '$(Build.ArtifactStagingDirectory)/target'
|
||||||
mavenAuthenticateFeed: false
|
artifactName: 'jar-artifact'
|
||||||
effectivePomSkip: false
|
publishLocation: 'Container' # Publishes inside Azure Pipelines artifact folder.
|
||||||
sonarQubeRunAnalysis: true
|
parallel: true # Increased speed through multi-threaded copying.
|
||||||
sqMavenPluginVersionChoice: 'latest'
|
parallelCount: 8 # Dependent upon CPU capabilities.
|
||||||
|
|
||||||
# Adds results and link to sonarcloud.io reports under 'Extensions' tab on pipeline run report.
|
- stage: CI
|
||||||
# see: https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud
|
displayName: 'Continuous Deployment'
|
||||||
- task: SonarCloudPublish@1
|
dependsOn: [CI]
|
||||||
displayName: 'Publish Quality Gate Result on SonarCloud'
|
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
|
||||||
inputs:
|
jobs:
|
||||||
pollingTimeoutSec: '300'
|
- job: DeployWebApp
|
||||||
|
displayName: Build Test and Deploy spring-petclinic Java Web App
|
||||||
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml
|
steps:
|
||||||
- task: CopyFiles@2
|
# Deploy JAR into Azure Web App Service https://docs.microsoft.com/en-us/azure/app-service/overview
|
||||||
displayName: 'Copy Files to artifact staging directory'
|
# Azure App Service offers a Web application hosting Platform-as-a-Service, offering:
|
||||||
inputs:
|
# - Security
|
||||||
SourceFolder: '$(System.DefaultWorkingDirectory)'
|
# - Load balancing
|
||||||
Contents: '**/target/*.?(war|jar)'
|
# - High Availability and autoscaling (based on policies)
|
||||||
TargetFolder: $(Build.ArtifactStagingDirectory)
|
# For pipeline configuration, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-rm-web-app?view=azure-devops
|
||||||
preserveTimestamp: true
|
- task: AzureWebApp@1
|
||||||
|
displayName: Deploy spring-petclinic to Azure Web App service
|
||||||
# Publish build artifacts to Azure Pipelines (Continuous Delivery).
|
inputs:
|
||||||
# Build artifacts are retained and can be downloaded for local use, or used in other stages or pipeline runs for deployments.
|
# For configuring Service Connection, see: https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml
|
||||||
# https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops
|
azureSubscription: 'azure-svc-connection'
|
||||||
- task: PublishBuildArtifacts@1
|
appType: webAppLinux
|
||||||
inputs:
|
appName: 'james-pet-clinic'
|
||||||
pathToPublish: '$(Build.ArtifactStagingDirectory)/target'
|
package: '$(System.DefaultWorkingDirectory)/**/*.jar'
|
||||||
artifactName: 'jar-artifact'
|
# Only deploy web app from main branch (for release purposes)
|
||||||
publishLocation: 'Container' # Publishes inside Azure Pipelines artifact folder.
|
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
|
||||||
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'))
|
|
||||||
...
|
...
|
||||||
|
|
Loading…
Reference in a new issue