【问题标题】:How to set a variable from another yaml file in azure-pipeline.yml如何从 azure-pipeline.yml 中的另一个 yaml 文件设置变量
【发布时间】:2020-09-15 12:04:54
【问题描述】:

我有一个如下所示的environment.yml,我想读出name变量(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

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

variables:
  tag: get the value of the name from the environment.yml aka 'core-force'

【问题讨论】:

    标签: azure-devops yaml azure-pipelines


    【解决方案1】:

    请查看example:

    文件:vars.yml

    variables:
      favoriteVeggie: 'brussels sprouts'
    

    文件:azure-pipelines.yml

    variables:
    - template: vars.yml  # Template reference
    
    steps:
    - script: echo My favorite vegetable is ${{ variables.favoriteVeggie }}.
    

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

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

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

    我在开发者社区找到了这个topic,您可以在这里阅读:

    Yaml 变量一直是字符串:字符串映射。该文档目前似乎是正确的,尽管您上次访问时我们可能遇到了错误。

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

    但我没有更多关于此的信息。

    【讨论】:

    • 是否可以利用模板来填充管道的其他部分作为矩阵策略?例如。动态地为每个文件创建一个作业,并使用 bash 脚本生成一个 yaml 以在其中使用 stackoverflow.com/q/70738819/3673430
    • 是的,应该可以。请查看here
    【解决方案2】:

    全局变量应存储在单独的模板文件中。理想情况下,此文件应位于单独的存储库中,其他存储库可以引用此文件。

    Here is another answer for this

    【讨论】:

      猜你喜欢
      • 2014-05-03
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2019-01-06
      • 2022-01-10
      • 2021-04-26
      • 1970-01-01
      相关资源
      最近更新 更多