如何在yaml文件的步骤部分中获取矩阵的工作名称?

时间:2019-11-25 13:17:01

标签: azure-devops azure-pipelines

我有一个非常简单的Azure Pipelines YAML文件,例如:

pool:
  vmImage: 'ubuntu-18.04'

strategy:
  matrix:
    debian:
      img: 'debian:latest'
    fedora:
      img: 'fedora:latest'
    arch:
      img: 'archlinux:latest'
    opensuse:
      img: 'opensuse/leap:latest'


container: $[ variables['img'] ]

steps:
  - script: printenv
    displayName: Dump env
  - script: make
    displayName: Build the project

除了在上面列出的四个容器中的每个容器上构建相同的项目外,别无所求。

它可以工作,但是我还想执行一个使用作业名称(debian,fedora等)来运行特殊脚本的步骤。

如何访问steps中的工作名称?是否有类似$(job)的东西?

1 个答案:

答案 0 :(得分:1)

您拥有pre-defined变量$(Agent.JobName)可以使用。例如:

steps:
  - script: echo $(Agent.JobName))
    displayName: echo $(Agent.JobName))

将给出以下输出:

enter image description here

enter image description here

enter image description here

enter image description here