提问人:Rakesh Kumar 提问时间:11/17/2023 更新时间:11/17/2023 访问量:30
使用 GitHub 操作部署 .NET 6 Web API:appsettings.json 未使用环境设置进行更新
Deploying .NET 6 Web API with GitHub Action: appsettings.json Not Updating with Environment Settings
问:
我的 GitHub Actions 工作流遇到了一个问题,即文件未在 Azure Web 应用上正确更新。尽管部署成功,但该文件并未反映相应环境设置中的预期值。我已经验证了存储库中的源文件是否正确。但是,当我在 kudo 控制台中交叉验证时,Azure Web 应用不会更新这些值。appsettings.json
appsettings.json
appsettings.json
appsetting.json
例如:当我选择设置时,它应该替换/更新文件中的值。appsettings.SIT.json
appsettings.json
以下是我的 GitHub 操作:
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 }}"
答: 暂无答案
评论