3

我在 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)

谢谢!

4

2 回答 2

1

卡辛​​再次出击!MyVariableName 在 Azure Devops 上变成了 MYVARIABLENAME。我将我组中的变量名更改为全部大写,它起作用了。我在这上面花了太多时间。

于 2020-04-25T21:04:13.813 回答
0

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

首先,我必须在以下位置创建新变量组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 groupsvariables defined in a yaml. 在这种情况下,您必须对单个(非分组)变量使用name/语法。value

请参阅Microsoft 变量组文档。这样的例子在那里得到了很好的解释。我还建议仔细查看通用变量文档

如果在其他任务中引用变量,这里是 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)

祝你好运!

于 2020-04-25T20:05:42.467 回答