Azure Devops - 如何将环境变量传递给 dotnet 测试?
Azure Devops - How to pass environment variables into dotnet test?
我在 Azure Devops 上有一个标准的 .NET Core (Ubuntu) 管道,在我的测试项目中,我使用环境变量。在我的管道中,我定义了我的组变量
variables:
- group: MyApiVariables
每当我 运行 我的项目测试时
- task: DotNetCoreCLI@2
displayName: "Testing Application"
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
没有传入实际的环境变量。它们是空白的。
为了得到这个 运行ning 我错过了什么?我什至在编辑管道页面中定义了变量,但运气不佳
- task: Bash@3
inputs:
targetType: 'inline'
script: echo $AppConfigEndpoint
env:
AppConfigEndpoint: $(AppConfigEndpoint)
ApiConfigSection: $(ApiConfigSection)
谢谢!
迈克,我看到你使用变量组。我认为这可能会导致您的问题。看一下我做的变量传递示例:
首先我必须在 Library
中创建新的变量组:
这是引用创建的变量的管道代码:
# Set variables group reference
variables:
- group: SampleVariableGroup
steps:
- powershell: 'Write-Host "Config variable=$(configuration) Platform variable=$(platform)"'
displayName: 'Display Sample Variable'
我使用 PowerShell 任务来验证变量是否正确传递给作业。
如您所见,configuration
和 platform
值均已正确显示。
事实上,你不会出错,除非你开始将 variable groups
与 variables defined in a yaml
混合使用。在这种情况下,您必须对单个 (non-grouped) 变量使用 name
/value
语法。
请参阅Microsoft Variable Groups documentation. Such example is well explained there. I also suggest to take closer look at general Variables Documentation。
如果在其他任务中引用变量,这里是 MS 的一个很好的例子(它应该以相同的方式在任何地方工作):
# Set variables once
variables:
configuration: debug
platform: x64
steps:
# Use them once
- task: MSBuild@1
inputs:
solution: solution1.sln
configuration: $(configuration) # Use the variable
platform: $(platform)
# Use them again
- task: MSBuild@1
inputs:
solution: solution2.sln
configuration: $(configuration) # Use the variable
platform: $(platform)
祝你好运!
CASING再次来袭! MyVariableName 在 Azure Devops 上变成了 MYVARIABLENAME。我将我组中的变量名称更改为全部大写并且它起作用了。我在这上面花了太多时间。
我在 Azure Devops 上有一个标准的 .NET Core (Ubuntu) 管道,在我的测试项目中,我使用环境变量。在我的管道中,我定义了我的组变量
variables:
- group: MyApiVariables
每当我 运行 我的项目测试时
- task: DotNetCoreCLI@2
displayName: "Testing Application"
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
没有传入实际的环境变量。它们是空白的。
为了得到这个 运行ning 我错过了什么?我什至在编辑管道页面中定义了变量,但运气不佳
- task: Bash@3
inputs:
targetType: 'inline'
script: echo $AppConfigEndpoint
env:
AppConfigEndpoint: $(AppConfigEndpoint)
ApiConfigSection: $(ApiConfigSection)
谢谢!
迈克,我看到你使用变量组。我认为这可能会导致您的问题。看一下我做的变量传递示例:
首先我必须在 Library
中创建新的变量组:
这是引用创建的变量的管道代码:
# Set variables group reference
variables:
- group: SampleVariableGroup
steps:
- powershell: 'Write-Host "Config variable=$(configuration) Platform variable=$(platform)"'
displayName: 'Display Sample Variable'
我使用 PowerShell 任务来验证变量是否正确传递给作业。
如您所见,configuration
和 platform
值均已正确显示。
事实上,你不会出错,除非你开始将 variable groups
与 variables defined in a yaml
混合使用。在这种情况下,您必须对单个 (non-grouped) 变量使用 name
/value
语法。
请参阅Microsoft Variable Groups documentation. Such example is well explained there. I also suggest to take closer look at general Variables Documentation。
如果在其他任务中引用变量,这里是 MS 的一个很好的例子(它应该以相同的方式在任何地方工作):
# Set variables once
variables:
configuration: debug
platform: x64
steps:
# Use them once
- task: MSBuild@1
inputs:
solution: solution1.sln
configuration: $(configuration) # Use the variable
platform: $(platform)
# Use them again
- task: MSBuild@1
inputs:
solution: solution2.sln
configuration: $(configuration) # Use the variable
platform: $(platform)
祝你好运!
CASING再次来袭! MyVariableName 在 Azure Devops 上变成了 MYVARIABLENAME。我将我组中的变量名称更改为全部大写并且它起作用了。我在这上面花了太多时间。