|
| 1 | +# This workflow will build and push a Java application to an Azure Web App when a commit is pushed to your default branch. |
| 2 | +# |
| 3 | +# This workflow assumes you have already created the target Azure App Service web app. |
| 4 | +# For instructions see https://docs.microsoft.com/en-us/azure/app-service/quickstart-java?tabs=javase&pivots=platform-linux |
| 5 | +# |
| 6 | +# To configure this workflow: |
| 7 | +# |
| 8 | +# 1. Download the Publish Profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal. |
| 9 | +# For more information: https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials |
| 10 | +# |
| 11 | +# 2. Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret. |
| 12 | +# For instructions on obtaining the publish profile see: https://docs.microsoft.com/azure/app-service/deploy-github-actions#configure-the-github-secret |
| 13 | +# |
| 14 | +# 3. Change the value for the AZURE_WEBAPP_NAME. Optionally, change the JAVA_VERSION environment variable below. |
| 15 | +# |
| 16 | +# For more information on GitHub Actions for Azure: https://github.com/Azure/Actions |
| 17 | +# For more information on the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy |
| 18 | +# For more samples to get started with GitHub Action workflows to deploy to Azure: https://github.com/Azure/actions-workflow-samples |
| 19 | + |
| 20 | +name: Build and deploy JAR app to Azure Web App |
| 21 | + |
| 22 | +env: |
| 23 | + AZURE_WEBAPP_NAME: your-app-name # set this to the name of your Azure Web App |
| 24 | + JAVA_VERSION: '11' # set this to the Java version to use |
| 25 | + DISTRIBUTION: zulu # set this to the Java distribution |
| 26 | + |
| 27 | +on: |
| 28 | + push: |
| 29 | + branches: [ "main" ] |
| 30 | + workflow_dispatch: |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +jobs: |
| 36 | + build: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v3 |
| 41 | + |
| 42 | + - name: Set up Java version |
| 43 | + |
| 44 | + with: |
| 45 | + java-version: ${{ env.JAVA_VERSION }} |
| 46 | + distribution: ${{ env.DISTRIBUTION }} |
| 47 | + cache: 'maven' |
| 48 | + |
| 49 | + - name: Build with Maven |
| 50 | + run: mvn clean install |
| 51 | + |
| 52 | + - name: Upload artifact for deployment job |
| 53 | + uses: actions/upload-artifact@v3 |
| 54 | + with: |
| 55 | + name: java-app |
| 56 | + path: '${{ github.workspace }}/target/*.jar' |
| 57 | + |
| 58 | + deploy: |
| 59 | + permissions: |
| 60 | + contents: none |
| 61 | + runs-on: ubuntu-latest |
| 62 | + needs: build |
| 63 | + environment: |
| 64 | + name: 'Development' |
| 65 | + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Download artifact from build job |
| 69 | + uses: actions/download-artifact@v3 |
| 70 | + with: |
| 71 | + name: java-app |
| 72 | + |
| 73 | + - name: Deploy to Azure Web App |
| 74 | + id: deploy-to-webapp |
| 75 | + uses: azure/webapps-deploy@v2 |
| 76 | + with: |
| 77 | + app-name: ${{ env.AZURE_WEBAPP_NAME }} |
| 78 | + publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} |
| 79 | + package: '*.jar' |
0 commit comments