3

I am struggling to replace values in my appsettings.json file and was wondering where I'm going wrong?

I have created two secrets in GitHub entitled COSMOSDBSETTINGS_SERVICEENDPOINT and COSMOSDBSETTINGS_AUTHKEY.

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

      - name: App Settings Variable Substitution
        uses: microsoft/variable-substitution@v1
        with:
          files: '${{env.DOTNET_ROOT}}\myapp\appsettings.json'
        env:
          CosmosDbSettings:ServiceEndpoint: ${{ secrets.COSMOSDBSETTINGS_SERVICEENDPOINT }}
          CosmosDbSettings:AuthKey: ${{ secrets.COSMOSDBSETTINGS_AUTHKEY }}

I get the error stating

Run microsoft/variable-substitution@v1
Applying variable substitution on JSON file: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\myapp\appsettings.json
Skipped updating file: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet\myapp\appsettings.json
Error: Error: Failed to apply variable substitution

This is the appsettings locally:

  "CosmosDbSettings": {
    "ServiceEndpoint": "https://localhost:8081/",
    "AuthKey": "KEY"
  },

1 Answer 1

5

Use a dot instead of a colon:

env:
  CosmosDbSettings.ServiceEndpoint: ${{ secrets.COSMOSDBSETTINGS_SERVICEENDPOINT }}
  CosmosDbSettings.AuthKey: ${{ secrets.COSMOSDBSETTINGS_AUTHKEY }}
Sign up to request clarification or add additional context in comments.

1 Comment

Or use double underscores, for example: CosmosDbSettings__ServiceEndpoint

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.