【问题标题】:Azure Devops - How to pass environment variables into dotnet test?Azure Devops - 如何将环境变量传递给 dotnet 测试?
【发布时间】:2020-04-25 18:59:35
【问题描述】:

我在 Azure Devops 上有一个标准的 .NET Core (Ubuntu) 管道,在我的测试项目中,我使用环境变量。在我的管道中,我已经像这样定义了我的组变量

variables:
- group: MyApiVariables

每当我为我的项目运行测试时

- task: DotNetCoreCLI@2
  displayName: "Testing Application"
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

没有传入实际的环境变量。它们是空白的。

让这个运行我缺少什么?我什至在编辑管道页面中也定义了变量,但没有运气

- task: Bash@3
  inputs:
    targetType: 'inline'
    script: echo $AppConfigEndpoint
  env:
    AppConfigEndpoint: $(AppConfigEndpoint)
    ApiConfigSection: $(ApiConfigSection)

谢谢!

【问题讨论】:

    标签: azure-devops environment-variables dotnet-test


    【解决方案1】:

    CASING再次出击! MyVariableName 在 Azure Devops 上变成了 MYVARIABLENAME。我将我组中的变量名更改为全部大写,并且有效。我花了太多时间在这上面。

    【讨论】:

    • 感谢您在这里分享您的解决方案,请您接受您的解决方案作为答案吗?因此,对于遇到相同问题的其他成员轻松找到解决方案将有所帮助。
    【解决方案2】:

    迈克,我看到你使用变量组。我认为这可能会导致您的问题。看看我做的变量传递示例:

    首先我必须在Library 中创建新的变量组:

    这是一个引用创建变量的管道代码:

    # Set variables group reference
    variables:
    - group: SampleVariableGroup
    
    steps:
      - powershell: 'Write-Host "Config variable=$(configuration) Platform variable=$(platform)"'
        displayName: 'Display Sample Variable'  
    

    我使用 PowerShell 任务来验证变量是否正确传递给作业。

    如您所见,configurationplatform 值均正确显示。

    事实上你不会出错,除非你开始混合variable groupsvariables defined in a yaml。在这种情况下,您必须对单个(非分组)变量使用 name/value 语法。

    请参阅Microsoft Variable Groups 文档。这样的例子在那里得到了很好的解释。我也建议仔细看看一般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)
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2021-02-18
      • 2013-12-29
      • 2021-01-15
      • 2016-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多