0

I use Azure to deploy my java web application. I use github CI/CD to deploy but when I commit and push new changes azure still doesn't update, it uses older version even though I have seen azure build and redeploy. How can I make Azure webapp update changes when I make a new commit to github. Help me!

I asked chatgpt or searched on google but couldn't find it, Hope you guys can help!

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • You need to run your Github actions for deployment. – Ajay Managaon Jul 09 '23 at 10:19
  • Have you set up [this pipeline](https://learn.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel)? If so, can you share your GitHub action logs? If not, can you share your GitHub action code? – Florian Vuillemot Jul 09 '23 at 19:05

1 Answers1

0

In order to trigger your github action workflow when the change happens in any of your JAVA app files, You can automatically trigger the workflow by adding this line as mentioned here in this Official Github document

on:
  push:
    branches:
      - 'main'
      - 'releases/**'    

If you want to trigger the workflow when the change happens to specific file in the workflow, You can use the script below:-

on:
  push:
    branches:
      - 'main'
      - 'releases/**'

One more option according to this SO thread answer by madhead is to use the method below:-

- uses: stefanzweifel/git-auto-commit-action@v4

Complete github workflow:-

You can find my complete github workflow here

Code:-

name: Build and deploy JAR app to Azure Web App - siliconwebapp098

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Java version
        uses: actions/setup-java@v1
        with:
          java-version: '17'

      - name: Build with Maven
        run: mvn clean install

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: java-app
          path: '${{ github.workspace }}/target/*.jar'

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: java-app

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'siliconwebapp098'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_163298DB206C4BA8AD04D70825D89253 }}
          package: '*.jar'

I tried above github workflow to deploy my Java sample in Azure Web app with runtime set to Java and the workflow was successful, Refer below:-

Output:-

enter image description here

I edited my App.java code and commited it, After the commit, Github action workflow got triggered automatically like below:-

enter image description here

enter image description here

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11