diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..ec8de4b --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,93 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- main +resources: +- repo: self +variables: + dockerfilePath: '$(Build.SourcesDirectory)/src/Dockerfile' + webRepository: 'web' + tag: '$(Build.BuildId)' + vmImageName: 'ubuntu-latest' +stages: +- stage: Build + displayName: Build and publish Java container + jobs: + - job: Build + displayName: Build + pool: + vmImage: $(vmImageName) + variables: + - group: Release + steps: + - task: Maven@3 + displayName: 'Maven pom.xml' + inputs: + options: '-DskipITs --settings ./maven/settings.xml' + publishJUnitResults: false + - task: CopyFiles@2 + displayName: Copy WAR file to staging directory + inputs: + sourceFolder: '$(build.sourcesdirectory)' + contents: | + target/myshuttledev*.war + *.sql + targetFolder: '$(build.artifactstagingdirectory)' + - task: Docker@2 + displayName: Build and push Java container image to registry + inputs: + command: buildAndPush + buildContext: '$(build.artifactstagingdirectory)' + repository: $(webRepository) + dockerfile: $(dockerfilePath) + containerRegistry: 'Container Registry Connection' + tags: | + $(tag) + - task: AzureMysqlDeployment@1 + displayName: Run MySQL initialization script + inputs: + azureSubscription: 'Azure Connection' + serverName: '$(MySqlServer).mysql.database.azure.com' + databaseName: 'alm' + sqlUsername: $(MySqlUserName)@$(MySqlServer) + sqlPassword: $(MySqlPassword) + sqlFile: '$(Build.SourcesDirectory)/CreateMYSQLDB.sql' +- stage: Deploy + displayName: 'Deploy Web App' + dependsOn: Build + condition: succeeded() + jobs: + - deployment: DeploymentJob + pool: + vmImage: $(vmImageName) + environment: java-container + variables: + - group: Release + strategy: + runOnce: + deploy: + steps: + - task: AzureWebAppContainer@1 + displayName: Update the web app with the new container + inputs: + appName: $(WebAppName) + azureSubscription: 'Azure Connection' + imageName: $(RegistryName)/$(webRepository):$(build.buildId) + - task: AzureAppServiceSettings@1 + displayName: Update web app connection string + inputs: + azureSubscription: 'Azure Connection' + appName: $(WebAppName) + resourceGroupName: 'java-containers-cicd-rg' + connectionStrings: | + [ + { + "name": "MyShuttleDb", + "value": "jdbc:mysql://$(MySqlServer).mysql.database.azure.com:3306/alm?useSSL=true&requireSSL=false&autoReconnect=true&user=$(MySqlUserName)@$(MySqlServer)&password=$(MySqlPassword)", + "type": "MySql", + "slotSetting": false + } + ] \ No newline at end of file