1

I have setup continuous deployment of my .net 6 api to Azure Web apps via a workflow on Github - for reference the base template is azure's "Build and deploy ASP.Net Core app to Azure Web App" Extracts below. I have tried to implement env and my firebase credentials in many different ways within this file (on the job, build, deploy, steps etc) with no success. The environment secret is setup on the GitHub environment but it never pulls through to the environment variables in my deployment. I must be missing something and the use of the azure deployment pipeline makes it harder for me follow and apply the solutions presented in the docs.

name: Build and deploy ASP.Net Core app to Azure Web App
on:
  push:
    branches:
      - Dev
  workflow_dispatch:


jobs:
  build:
    runs-on: windows-latest
    env:
        GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.FIREBASE_CONFIG }}


    steps:
      - uses: actions/checkout@v4

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

        ....

      - name: Env Build Step
        run: echo $GOOGLE_APPLICATION_CREDENTIALS
        
  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Development'
      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

        ....

1 Answer 1

0

You can access your Google Application Credentials by referring to this SO thread answer by Clinton nirju. Or directly echo the secret by referring to my workflow below which deploys .Net API into Azure Web App.

My Github Action Workflow:-

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

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: '6.0.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: Print Google Application Credentials
        run: echo ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}
      
      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: 'webapp-apij'
          slot-name: 'Production'
          package: .
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_4A9DDE8496AC4AD9AFBB31EC2E272AF0 }}

Output:-

enter image description here

You can also add your Google Application secret to your Azure Web app directly by adding app-settings in your Deploy Azure Web app task like below:-

- name: Deploy to Azure Web App
  id: deploy-to-webapp
  uses: azure/webapps-deploy@v2
  with:
    app-name: 'valleyapp-api'
    slot-name: 'Production'
    package: .
    publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D9DE298E2BD642E3821D279D2C59C3F8 }}
    app-settings: '{"GOOGLE_APPLICATION_CREDENTIALS": "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}", "Setting1": "Value1", "Setting2": "Value2"}'

My secret:-

enter image description here

Reference:-

Using secrets in GitHub Actions - GitHub Docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.