Thursday, April 18, 2024

GitHub Actions CICD Pipeline to Deploy Java WebApp into Azure App Service | Integration GitHub Actions with Azure App Service


What are we going to do in this lab?
1. Create a Web App in Azure Cloud
2. Configure WebApp to Deploy using gitHub Actions
3. Create workflow yaml
4. Add steps/tasks in the yaml file
5. Run the workflow yaml
6. Check if Java Web App is deployed in Azure App Service

How to Create WebApp in Azure Portal?

1. Login
2. Click on App services

3.Click on + Add or click on Create app service

Click on Web App. Choose your Azure subscription, usually Pay as you Go or Free trial subscription
Create a new resource group or you can use existing resource group)

Enter App service name(it should be unique)
Publish as Code
Run time stack as Java 17
Java Web Server stack --> Tomcat 10.0
Operating System as Linux
Region as Central US or where ever you are based at

Enter LinuxPlan name
Choose pricing plan

Now go to Deployment tab:
Enable basic authentication
and enable Continuous Deployment 

Click on GitHub account, Authorize.
Authorize AzureappService
now select organization, repo, branch

You can also click on preview file to get pipeline YAML code 

Click on Review and Create

Create Web App
Now make sure AzureAppService_PublishProfile secret is automatically created in GitHub repo you selected.

Create GitHub Actions CICD workflow yaml:

name: Build and deploy WAR app to Azure Web App
      - main
    runs-on: ubuntu-latest
      - uses: actions/checkout@v4
      - name: Set up Java version
        uses: actions/setup-java@v2
          java-version: '11'
          distribution: 'adopt'
      - name: Build with Maven
        run: mvn clean install -f MyWebApp/pom.xml
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
          name: MyWebApp
          path: '${{ github.workspace }}'
    runs-on: ubuntu-latest
    needs: build
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
          name: MyWebApp
      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
          app-name: 'spingbootwebapp'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_76B948D486E54ED7B06775D572207D40 }}
          package: '*.war'

Check the output after running the pipeline:

Verify if WebApp has been deployed into Azure App Service by browsing Web App url.

Watch here all the steps in YouTube channel:

No comments:

Post a Comment

Top 10 DevOps Popular Tools | Popular DevOps Tools You Must Know In 2024 | Learn DevOps Tools in 2024

Here are the top 10 DevOps Tools to focus on to put your DevOps learning on a  faster track  and kick start your career quickly as a success...