Search code examples
asp.net-mvcerror-handlingazure-web-app-servicegithub-actionsworkflow

Running incorrect file on Azure through Github Actions Workflow ASP .Net multifile project


i am trying to deploy my ASP .Net MVC Core web-app to Azure through Github actions. When running it on localhost everything works, but when deploying (the deploy process goes perfectly) to Azure it shows the error 500. enter image description here

I have set connection string and everything well (i guess), I think there could be problems with my Workflow. When trying to check it from Kudu and run the file that i run on localhost it works finemy Web file is the main one

I have tried writing different things in my Workflow, which looks like this:

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy ASP.Net Core app to Azure Web App - instbyden

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest
    
    steps:
      - uses: actions/checkout@v4

      - name: Set up .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: '7.x'
          include-prerelease: true

      - name: Build with dotnet
        run: dotnet build --configuration Release

      - name: dotnet publish
        run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: .net-app
          path: ${{env.DOTNET_ROOT}}/myapp

  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: .net-app
      
      - name: Login to Azure
        uses: azure/login@v1
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_6E7DB23ABB7C46C581EBCFE4FB00E6F3 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_D582151191524D76A669EB69D9D63985 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_F9EFD9D768594B54B60D373563613D0F }}

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'instbyden'
          slot-name: 'Production'
          package: .

Here is the link to my GitHub project: https://github.com/gr1gor1ychuk/Hryhoriichuk.University.Instagram

(i tried checking logs for that error 500, but they are useless)


Solution

  • I tried your code, made few changes, and was able to deploy the app to Azure App Service via GitHub actions.

    This is my .yml file :

    name: Build and deploy ASP.Net Core app to Azure Web App - Dotnetapptest
    on:
    push:
    branches:
    - master
    workflow_dispatch:
    jobs:
    build:
    runs-on: windows-latest
    steps:
    - uses: actions/checkout@v4
    - name: Set up .NET Core
    uses: actions/setup-dotnet@v1
    with:
    dotnet-version: '8.x'
    include-prerelease: true
    - name: Build with dotnet
    run: dotnet build --configuration Release
    - name: dotnet publish
    run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
    - name: Upload artifact for deployment job
    uses: actions/upload-artifact@v3
    with
    name: .net-app
    path: ${{env.DOTNET_ROOT}}/myapp
    deploy:
    runs-on: windows-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@v3
    with:
    name: .net-app
    - name: Deploy to Azure Web App
    id: deploy-to-webapp
    uses: azure/webapps-deploy@v2
    with:
    app-name: 'Dotnetapptest'
    slot-name: 'Production'
    publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_7DFA6BD4ADDE43EA98EAC01EEFCA5CD0 }}
    package: .
    

    Ensure that you add the ClientID and Client Secret correctly in your application settings for your Azure App Service.

    enter image description here

    I deployed the app through GitHub.

    enter image description here

    This is local output :

    enter image description here

    Here's the output after deployment:

    enter image description here

    enter image description here