Azure Devops 部署管道:访问不同作业中的输出变量

Azure Devops deployment pipeline: access output variable in different job

使用 Azure Devops 2019 服务器(本地)

所以我想要我的无代理工作,仅当 IsServiceInstalled 变量为 0 时,用户干预任务名为“安装”到 运行。我只能在同一工作中使用此变量(代理),但不在其他(无代理)内。

无论我做什么,我都会得到一个异常,说明如下:

Exception Message: Unrecognized value: 'dependencies'. Located at position 21 within expression: and(succeeded(), eq(<whatever i try to put here>, 0))

设置变量的代码:

#Sets IsServiceInstalled to determine if service must be installed or updated

Get-Service "$(RabbitMQServiceName)" -ErrorAction SilentlyContinue
if ($?) {
  echo "##vso[task.setvariable variable=IsServiceInstalled;isOutput=true]1"
} else {
  echo "##vso[task.setvariable variable=IsServiceInstalled;isOutput=true]0"
}

任务本身:

  1. 我知道我可以使用“依赖项”。访问该变量。 Use the output variable from a job in a condition in a subsequent job。但是我没有为 Job 命名的选项。
  2. 我 运行 我的部署 system.debug=true 并发现 [SYSTEM_JOBNAME] --> [__default] - 所以我尝试使用 and(succeeded(), eq(dependencies.__default.Outputs['IsServiceInstalledTask.IsServiceInstalled'], 0)) 设置 - 是的,我得到异常 Unrecognized value: 'dependencies' - 毫不奇怪,因为我从未指定依赖项,而且我看不到可以在 UI.
  3. 中指定它的位置
  4. 我没有设置作业名称的选项,所以我尝试设置在调试日志中找到的各种值(__default 是我想要输出变量的作业名称):Stage_cb7edb91b40b4747845ae3564bf62723_2_9.Phase_1.__default...Phase_1.__default...__default...

无论我尝试什么,我都会得到相同的无法识别的值异常。

写问题的好处是我在官方文档中找到了答案:经典管道中不支持

让我引用:

Use output variables from tasks

Some tasks define output variables, which you can consume in downstream steps, jobs, and stages. In YAML, you can access variables across jobs and stages by using dependencies..

Use outputs in the same job

In the Output variables section, give the producing task a reference name. Then, in a downstream step, you can use the form $(.) to refer to output variables.

Use outputs in a different job

You must use YAML to consume output

Use output variables from tasks 并单击“经典”选项卡