I am facing an issue with my GitHub Actions workflow where the appsettings.json
file is not updating correctly on an Azure Web App. Despite a successful deployment, the appsettings.json
file doesn’t reflect the expected values from the corresponding environment settings. I have verified that the source appsettings.json
file in the repository is correct. However, the Azure Web App doesn’t update the appsetting.json
values when I cross verified in kudo console.
For example: When I am selecting appsettings.SIT.json
settings then it should replace/update values in appsettings.json
file.
Following is my GitHub action:
name: Build ASP.NET code (Web App for WebAPI)
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
type: environment
required: true
app-configuration:
type: choice
description: Select App Settings File
default: 'appsettings.Development.json'
options:
- appsettings.Development.json
- appsettings.SIT.json
required: true
env:
AZURE_WEBAPP_WEBAPI_NAME: ${{ secrets.AZURE_WEBAPP_WEBAPI_NAME }}
CERT: ${{ secrets.CERT }}
WORKING_DIRECTORY: src/Test.WebApi
BUILD_CONFIGURATION: ${{ inputs.build-configuration }}
#NUGET_VERSION: 4.4.1
CLIENT_ID: ${{ secrets.CLIENT_ID }}
TENANT_ID: ${{ secrets.TENANT_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
JSON_PATH: ${{ inputs.app-configuration }}
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Navigate to Workspace
run: cd ${{ env.WORKING_DIRECTORY }}
- name: Create Build Directory
run: mkdir _build
- name: Build Project
run: dotnet build ${{ env.WORKING_DIRECTORY }}/Test.WebApi.sln --property:OutputPath="../_build" --configuration Release
- name: Test Project
run: dotnet test ${{ env.WORKING_DIRECTORY }}/Test.WebApi.Tests --no-restore --verbosity normal
- name: Upload artifact
uses: actions/[email protected]
with:
name: ASP-app
path: "${{ env.WORKING_DIRECTORY }}/_build"
deploy-to-staging-slot:
runs-on: ubuntu-latest
needs: build
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
# Logs in with below Azure credentials
- name: login to az
shell: bash
run: |
echo "$CERT" > sfh-mvc-cert.pem
az login --service-principal -u $CLIENT_ID -p sfh-mvc-cert.pem --tenant $TENANT_ID
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: ASP-app
path: download/ASP-app
- name: test
run: |
cd download/ASP-app
echo "listing ASP-app"
ls
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/[email protected]
with:
app-name: ${{ env.AZURE_WEBAPP_WEBAPI_NAME }}
package: download/ASP-app
slot-name: staging
- name: Deafult WebApp Configuration from appsettings.json
uses: azure/CLI@v1
with:
azcliversion: 2.42.0
inlineScript: |
az webapp config appsettings set -g "${{ env.RESOURCE_GROUP }}" -n '${{ env.AZURE_WEBAPP_WEBAPI_NAME }}' --settings "@Test.WebApi/Test.WebApi/appsettings.json" -s staging
- name: WebApp Configuration
uses: azure/CLI@v1
with:
azcliversion: 2.42.0
inlineScript: |
az webapp config appsettings set -g "${{ env.RESOURCE_GROUP }}" -n '${{ env.AZURE_WEBAPP_WEBAPI_NAME }}' --settings "@Test.WebApi/Test.WebApi/${{ env.JSON_PATH }}" -s staging
deploy-to-production-slot:
runs-on: ubuntu-latest
needs: deploy-to-staging-slot
environment: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: login to az
shell: bash
run: |
echo "$CERT" > sfh-mvc-cert.pem
az login --service-principal -u $CLIENT_ID -p sfh-mvc-cert.pem --tenant $TENANT_ID
- name: 'Swap Slots: ${{ env.AZURE_WEBAPP_WEBAPI_NAME }}'
uses: Azure/[email protected]
with:
inlineScript: az webapp deployment slot swap --resource-group ${{ env.RESOURCE_GROUP }} --name ${{ env.AZURE_WEBAPP_WEBAPI_NAME }} --slot staging --target-slot production
- name: Deafult WebApp Configuration from appsettings.json
uses: azure/CLI@v1
with:
azcliversion: 2.42.0
inlineScript: |
az webapp config appsettings set -g "${{ env.RESOURCE_GROUP }}" -n '${{ env.AZURE_WEBAPP_WEBAPI_NAME }}' --settings "@Test.WebApi/Test.WebApi/appsettings.json"
- name: WebApp Configuration
uses: azure/CLI@v1
with:
azcliversion: 2.42.0
inlineScript: |
az webapp config appsettings set -g ${{ env.RESOURCE_GROUP }} -n '${{ env.AZURE_WEBAPP_WEBAPI_NAME }}' --settings "@Test.WebApi/Test.WebApi/${{ env.JSON_PATH }}"