[英].NET User Secrets in GitHub Actions variables
I have this issue with .NET build pipeline on GitHub actions that fail in the test phase.我在测试阶段失败的 GitHub 操作上遇到 .NET 构建管道的问题。 The problem is that locally I use User Secrets configured using the structured JSON. Therefore I need to provide the replacement in GitHub Actions using the secrets that live in the scope of the Action lifetime.
问题是我在本地使用使用结构化 JSON 配置的用户机密。因此我需要使用存在于操作生命周期 scope 中的机密在 GitHub 操作中提供替换。
In Bitbucket, I could simulate the structure of the JSON nesting using the __
resolving into correct namespaces;在 Bitbucket 中,我可以使用
__
解析为正确的命名空间来模拟 JSON 嵌套的结构; however, this option does not seem to work on GitHub actions.但是,此选项似乎不适用于 GitHub 操作。
Example JSON:示例 JSON:
{
"IntegrationTest": {
"B2CPolicy": "https://example.com",
"ClientId": "some_client_id"
}
}
Where I would assume the variable INTEGRATIONTEST__B2CPOLICY
should be placed into the GitHub actions secrets.我假设变量
INTEGRATIONTEST__B2CPOLICY
应该放入 GitHub 操作机密中。
The do.net.yaml: do.net.yaml:
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: .NET
on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]
jobs:
build:
env:
SLN_FILE: "./src/be/proj.sln"
REPORTS_PATH: "./test-reports/build_$GITHUB_RUN_ATTEMPT"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore $SLN_FILE
- name: Generate client for test project
run: pwsh -File "./src/be/scripts/nswag/generate_data_for_test_project.ps1"
- name: Build
run: dotnet build --no-restore --configuration Release $SLN_FILE
- name: Test
run: dotnet test --no-build --verbosity normal --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose" $SLN_FILE
Any clue where is the possible problem?任何线索可能的问题在哪里?
Could it be caused by using encrypted secrets?会不会是使用加密密文引起的?
Thanks for any ideas.感谢您的任何想法。
Secrets are not automatically available as environment variables in all your actions, you need to add them.秘密不会在您的所有操作中作为环境变量自动可用,您需要添加它们。 Something like this should do it.
应该这样做。
- name: Test
env:
INTEGRATIONTEST__B2CPOLICY: ${{ secrets.INTEGRATIONTEST__B2CPOLICY }}
run: dotnet test --no-build --verbosity normal --configuration Release --test-adapter-path:. --logger:"junit;LogFilePath=$REPORTS_PATH/junit.xml;MethodFormat=Class;FailureBodyFormat=Verbose" $SLN_FILE
For more info: https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow更多信息: https://docs.github.com/en/actions/security-guides/encrypted-secrets#using-encrypted-secrets-in-a-workflow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.