在步骤条件中使用矩阵环境变量的 Azure 管道

Car*_*rch 5 azure-devops azure-pipelines

在我的 Azure DevOps 管道中,我有以下内容:

strategy:
  matrix:
    unit_test_linux:
      imageName: 'ubuntu-16.04'
      TYPE: 'unit'
    cucumber:
      imageName: 'ubuntu-16.04'
      TYPE: 'cucumber'
Run Code Online (Sandbox Code Playgroud)

我想TYPE在步骤条件下使用,有点像下面,我该怎么做?

- bash: |
    set -ev
    cd ./client
    npm install
  displayName: install
  env:
    DISPLAY: ':99.0'
  condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'), eq(${{'TYPE'}}, 'unit'))``
Run Code Online (Sandbox Code Playgroud)

Sha*_*zyk 5

矩阵变量就像每个变量一样,因此:

condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'), eq(variables['TYPE'], 'unit'))
Run Code Online (Sandbox Code Playgroud)

  • 它**不像**像_every_变量。澄清一下,它仅在_runtime_上可用。例如,您不能在条件模板中使用矩阵变量。但是您可以在允许使用 _runtime_ 变量的地方使用它们。_编译时_变量(例如`variables['Agent.IS']`)可以在任何地方使用。更多详细信息可以在 /sf/ask/4275537871/ 中找到 (2认同)