如何从 azure-pipeline.yml 中的另一个 yaml 文件设置变量

SLN*_*SLN 2 yaml azure-devops azure-pipelines

我有一个如下所示的environment.yml,我想读出名称变量(core-force)的内容并将其设置为我的azure-pipeline.yamal文件中的全局变量的值,我该怎么做?

name: core-force
channels:
  - conda-forge
dependencies:
  - click
  - Sphinx
  - sphinx_rtd_theme
  - numpy
  - pylint
  - azure-cosmos
  - python=3
  - flask
  - pytest
  - shapely
Run Code Online (Sandbox Code Playgroud)

在我的 azure-pipeline.yml 文件中我想要类似的东西

variables:
  tag: get the value of the name from the environment.yml aka 'core-force'
Run Code Online (Sandbox Code Playgroud)

Krz*_*tof 7

请检查这个例子

文件:vars.yml

variables:
  favoriteVeggie: 'brussels sprouts'
Run Code Online (Sandbox Code Playgroud)

文件:azure-pipelines.yml

variables:
- template: vars.yml  # Template reference

steps:
- script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.
Run Code Online (Sandbox Code Playgroud)

请注意,变量是简单的字符串,如果您想使用列表,您可能需要在 powershell 中在您想要使用该列表中的值的地方进行一些工作。

如果您不想使用上面所示的模板功能,您需要执行以下操作:

  • 创建一个单独的工作/阶段
    • 定义步骤以使用 REST API 或 Azure CLI 读取environment.yml文件并设置变量
  • 创建另一个工作/阶段并将当前的构建定义移动到那里

我在开发者社区中找到了这个主题,您可以在其中阅读:

Yaml 变量始终是 string: string 映射。该文档目前看来是正确的,尽管您上次访问时我们可能遇到了错误。

我们准备在不久的将来发布一个功能,让您可以通过更复杂的结构。敬请关注!

但我没有这方面的更多信息。