Azure Devops 管道:从模板导入变量并在同一变量块中声明变量

Xia*_*ZHU 9 azure-devops azure-pipelines

有什么方法可以将变量重用与模板和变量声明混合在同一个variables块中吗?像这样的东西:

variables:
  - template: vars.yml  # Template reference
  anotherVar: http://$(oneVarFromVarsYml)/xxx
Run Code Online (Sandbox Code Playgroud)

测试后发现不行,请问有什么解决办法吗?我知道我可以定义 varanotherVar 我知道我可以在同一个模板中vars.yml,但我需要直接在此处定义它而不是在模板中。

下面的官方 Azure Devops 文档仅提供了如何从模板导入变量,但没有提供混合模板变量和直接变量的示例: https: //learn.microsoft.com/en-us/azure /devops/pipelines/process/templates?view=azure-devops#variable-reuse

sil*_*ent 12

是的,应该有效。我也在做类似的事情。

variables:
- template: config/configuration.yaml  # contains (amongst others) a var "bar"

- name: 'testVar'
  value: 'foo-$(bar)'
Run Code Online (Sandbox Code Playgroud)


小智 3

Azure 文档的这一部分提到了它:

如果您同时使用变量和变量组,请使用name/value各个非分组变量的语法:

YAML

variables:
- group: my-variable-group
- name: my-bare-variable
  value: 'value of my-bare-variable'
Run Code Online (Sandbox Code Playgroud)

参考: https: //learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups ?view=azure-devops&tabs=yaml#use-a-variable-group