pipeline update

This commit is contained in:
Robert Sutton 2021-05-25 14:13:59 -04:00
parent 612ff07113
commit 9d927fdfb9

View file

@ -3,22 +3,29 @@
# Add steps that analyze code, save build artifacts, deploy, and more: # Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/java # https://docs.microsoft.com/azure/devops/pipelines/languages/java
# WORKING THEORY:
# Check if build is main branch, run prod template
# If build is any other branch, run dev template
# Otherwise, assume pull request trigger, run test template
trigger: trigger:
branches: branches:
include: include:
- main - '*' # must quote since "*" is a YAML reserved character; we want a string
variables: variables:
# Boolean: true if the detected branch is main
isMain: $[eq(variables['Build.SourceBranch'], 'refs/heads/main')]
# Azure Resource Manager connection created during pipeline creation # Azure Resource Manager connection created during pipeline creation
azureSubscription: '22796952-c4ae-4c29-bdff-8099e49d9c2a' azureSubscription: '22796952-c4ae-4c29-bdff-8099e49d9c2a'
# Production Web app name
webAppNameProd: 'java-pet-clinic'
# Production Environment name
environmentNameProd: 'java-pet-clinic'
# Web app name # Web app name
webAppName: 'java-pet-clinic' webAppNameDev: 'java-pet-clinic-dev'
# Environment name # Environment name
environmentName: 'java-pet-clinic' environmentNameDev: 'java-pet-clinic-dev'
# Agent VM image name # Agent VM image name
vmImageName: 'ubuntu-latest' vmImageName: 'ubuntu-latest'
@ -30,7 +37,6 @@ stages:
displayName: Maven Package and Publish Artifacts displayName: Maven Package and Publish Artifacts
pool: pool:
vmImage: $(vmImageName) vmImage: $(vmImageName)
steps: steps:
- task: Maven@3 - task: Maven@3
displayName: 'Maven Package' displayName: 'Maven Package'
@ -47,14 +53,15 @@ stages:
- upload: $(Build.ArtifactStagingDirectory) - upload: $(Build.ArtifactStagingDirectory)
artifact: drop artifact: drop
# Deploy to prod if "isMain" == true
- stage: Deploy - stage: Deploy
displayName: Deploy stage displayName: Deploy stage
dependsOn: Build dependsOn: Build
condition: succeeded() condition: and(succeeded(), eq(variables.isMain, true))
jobs: jobs:
- deployment: DeployLinuxWebApp - deployment: DeployLinuxWebApp
displayName: Deploy Linux Web App displayName: Deploy Linux Web App
environment: $(environmentName) environment: $(environmentNameProd)
pool: pool:
vmImage: $(vmImageName) vmImage: $(vmImageName)
strategy: strategy:
@ -66,5 +73,28 @@ stages:
inputs: inputs:
azureSubscription: $(azureSubscription) azureSubscription: $(azureSubscription)
appType: webAppLinux appType: webAppLinux
appName: $(webAppName) appName: $(webAppNameProd)
package: '$(Pipeline.Workspace)/drop/**/target/*.?(war|jar)'
# Deploy to dev if "isMain" == false
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: DeployLinuxWebApp
displayName: Deploy Linux Web App
environment: $(environmentNameDev)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Azure Web App Deploy: java-pet-clinic-dev'
inputs:
azureSubscription: $(azureSubscription)
appType: webAppLinux
appName: $(webAppNameDev)
package: '$(Pipeline.Workspace)/drop/**/target/*.?(war|jar)' package: '$(Pipeline.Workspace)/drop/**/target/*.?(war|jar)'