Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure pipeline yml file for automated deployment of spring-boot application with mysql database
trigger:
branches:
include:
- master
- releases/*
- feature/azure-devops
paths:
exclude:
- README.md
pool:
vmImage: 'ubuntu-latest'
variables:
subscription: <your-az-subscription>
resource.group: <resource-group-name>
app.name: <application-name>
appservice.plan: journeysaatscaleapps
mysql.db.name: <mysql-db-name>
mysql.db.server: <mysql-db-server-name>
mysql.db.username: <mysql-username>
rg.location: <your-azure-location>
acr.name: <your-acr-name>
registry.username: <your-acr-name>
MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
MAVEN_OPTS: '-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
stages:
- stage: InfraSetup
jobs:
- job: Setup_DB_ACR
displayName: Setup DB and ACR
steps:
- checkout: none
- task: AzureCLI@2
displayName: 'Create or Update MySQL DB'
inputs:
azureSubscription: $(subscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az group create -n $(resource.group) -l $(rg.location)
az acr create -g $(resource.group) -n $(acr.name) --sku Basic --admin-enabled true
az extension add --name db-up
az mysql up -g $(resource.group) -s $(mysql.db.server) -d $(mysql.db.name) -u $(mysql.db.username) -p $(mysql.db.password)
- stage: BuildDockerImages
jobs:
- job: ContainerImages
displayName: Build & Push Container Images
steps:
- task: Cache@2
displayName: Cache Maven local repo
inputs:
key: 'maven | "$(Agent.OS)" | **/pom.xml'
restoreKeys: |
maven | "$(Agent.OS)"
maven
path: $(MAVEN_CACHE_FOLDER)
- task: Maven@3
displayName: 'Build Image'
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean package jacoco:report'
options: '$(MAVEN_OPTS)'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
- task: PublishCodeCoverageResults@1
displayName: 'Publish Coverage Report'
inputs:
codeCoverageTool: 'JaCoCo'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/target/site/jacoco/jacoco.xml'
pathToSources: '$(System.DefaultWorkingDirectory)/src/main/java/'
reportDirectory: '$(System.DefaultWorkingDirectory)/target/site/jacoco'
- task: Maven@3
displayName: 'Push Image'
inputs:
mavenPomFile: 'pom.xml'
options: $(MAVEN_OPTS)
goals: 'dockerfile:push@push-latest dockerfile:push@push-version -Ddockerfile.username=$(registry.username) -Ddockerfile.password=$(dockerfile.password)'
publishJUnitResults: false
javaHomeOption: 'JDKVersion'
mavenVersionOption: 'Default'
mavenAuthenticateFeed: false
effectivePomSkip: false
sonarQubeRunAnalysis: false
- stage: Deployment
jobs:
- job: DeployService
displayName: 'Update webapp'
steps:
- checkout: none
- task: AzureCLI@2
displayName: 'Deploy Service'
inputs:
azureSubscription: $(subscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp create -g $(resource.group) -p $(appservice.plan) -n $(app.name) -i pipelinedemoacr.azurecr.io/pipeline-demo:latest -s $(registry.username) -w $(registry.password)
az webapp config appsettings set -g $(resource.group) -n $(app.name) --settings WEBSITES_PORT=8080
az webapp config connection-string set -g $(resource.group) -n $(app.name) -t MySql --settings HOST=$(mysql.db.server).mysql.database.azure.com USER=$(mysql.db.username)@$(mysql.db.server) PASSWORD=$(mysql.db.password)
az webapp start -g $(resource.group) -n $(app.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment