自定义管道资源变量

custom pipeline resource variables

我有一个 Azure 管道,它使用另一个管道生成的工件。像这样

resources:
  pipelines:
  - pipeline: BuildPipeline
    source: project-ci

有了这个引用,我可以引用一些管道资源变量,比如resources.pipeline.BuildPipeline.runName

问题是,除了预定义变量 (list here) 之外,是否可以在第一个管道中发布自定义变量以便稍后作为资源变量使用?

The question is, other than the predefined variables (list here), is it possible to publish a custom variable in the first pipeline so it's available later as a resource variable?

目前恐怕还没有直接在第一个管道中将自定义变量发布为资源变量的方法。

作为解决方法,我们可以在资源管道中使用 REST API 来更新当前管道的“变量”选项卡中的变量。

步骤:

  • 在后面的管道定义Variable中定义一个变量

  • 在资源管道中添加调用REST API (Definitions - Update)的任务,以在以后的发布管道中更新上述变量的值。

  • 在后面的管道中使用后面管道变量的更新值

使用RESTAPI更新定义变量值的详细信息,可关注下方工单:

或者您可以使用 Azure CLI 更新变量:

az pipelines variable update --name
                             [--allow-override {false, true}]
                             [--detect {false, true}]
                             [--new-name]
                             [--org]
                             [--pipeline-id]
                             [--pipeline-name]
                             [--project]
                             [--prompt-value {false, true}]
                             [--secret {false, true}]
                             [--subscription]
                             [--value]