将输出传递给 azure 发布管道中的新作业

时间:2021-03-03 04:29:32

标签: azure azure-devops azure-pipelines devops release

我正在寻找一些帮助,将 powershell 脚本的输出传递到发布管道中的另一个任务。

工作流程如下:

enter image description here

我需要将一个从 powershell 脚本创建的变量传递到手动干预文本消息中。

在 yaml 管道中,我会使用

  Write-Host "##vso[task.setvariable variable=myvar;isOutput=true]foo"

但是,为了访问它,它仅在前一个任务是依赖项时才有效,我不相信您可以在发布管道中做到这一点。

1 个答案:

答案 0 :(得分:1)

我不认为这是真的。在 YAML 管道中,您可以在根、阶段和作业级别设置变量。您还可以使用 variable group 使变量跨多个管道可用。某些任务定义了输出变量,您可以在下游步骤、作业和阶段中使用这些变量。

来到 YAML,您可以使用 dependencies 访问跨作业和阶段的变量。默认情况下,管道中的每个阶段都依赖于 YAML 文件中它之前的阶段。如果您需要引用不在当前阶段之前的阶段,您可以通过向阶段添加 dependsOn 部分来覆盖此自动默认值。

例如,假设我们有一个名为 MyTask 的任务,它设置了一个名为 MyVar 的输出变量。要在不同的作业中使用输出:

jobs:
 - job: A
  steps:
  # assume that MyTask generates an output variable called "MyVar"
  # (you would learn that from the task's documentation)
 - task: MyTask@1
    name: ProduceVar  # because we're going to depend on it, we need to name the step
 - job: B
  dependsOn: A
  variables:
    # map the output variable from A into this job
    varFromA: $[ dependencies.A.outputs['ProduceVar.MyVar'] ]
  steps:
 - script: echo $(varFromA) # this step uses the mapped-in variable

有关语法和示例的更多详细信息,请查看以下文章:

相关问题