解决多个变量组中的 Azure YAML Pipeline 重叠变量名称 [英] Resolve Azure YAML Pipeline overlapping variable names in multiple variable groups

查看:13
本文介绍了解决多个变量组中的 Azure YAML Pipeline 重叠变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力将我们的经典 Azure 管道转换为 YAML 管道.不清楚的一点是,如何保证两个同名但含义不同的变量组不相互踩踏.

We're working on converting our Classic Azure Pipelines to YAML Pipelines. One thing that is not clear is how to ensure that two different variable groups with variables with the same name but different meaning don't step on each other.

例如,如果我有变量组 vg1vg2,每个变量都有名为 secretDataDestination 的变量,我如何确保正确的 secretDataDestination 在 YAML Pipeline 中使用?

For example, if I have variable groups vg1 and vg2, each with variable named secretDataDestination, how do I ensure that the correct secretDataDestination is used in a YAML Pipeline?

一个更令人担忧的例子是,如果我们最初有两个变量组没有重叠的变量名称,我们如何确保将新重叠的变量名称添加到组中不会取代使用变量是否符合最初的预期?

A more concerning example is, if we initially have two variable groups without overlapping variable names, how do we ensure that adding a newly-overlapping variable name to a group doesn't replace use of the variable as originally intended?

推荐答案

如果我有变量组 vg1 和 vg2,每个组都有名为 secretDataDestination 的变量,我如何确保在 YAML 管道中使用正确的 secretDataDestination?

if I have variable groups vg1 and vg2, each with variable named secretDataDestination, how do I ensure that the correct secretDataDestination is used in a YAML Pipeline?

无论我们使用经典模式还是 YAML,不建议在不同的变量组中定义同名的变量.因为当你在同一个管道中引用包含相同变量名的不同变量组时,不能避免相互踩踏.

Whether we use classic mode or YAML, it is not recommended to define a variable with the same name in different variable groups. Because when you refer to different variable groups containing the same variable name in the same pipeline, you cannot avoid step on each other.

当你在同一管道的不同变量组中使用相同的变量名时,就像马特说的那样,

When you use the same variable name in different variable group in the same pipeline, just like Matt said,

您可以在同一管道中引用多个变量组.如果多个变量组包含同一个变量,变量组最后包含在您的 YAML 文件中将设置变量的值."

"You can reference multiple variable groups in the same pipeline. If multiple variable groups include the same variable, the variable group included last in your YAML file will set the variable's value."

variables:
- group: variable-group1
- group: variable-group2

也就是说后面写入的变量组中的变量值会覆盖先写入的变量组中的变量值

That means that the variable value in the variable group written later will overwrite the variable value in the variable group written first

我想您已经知道这一点,所以您发布了第二个问题.现在让我们转向第二个问题.

I guess you already know this, so you post your second question. Let us now turn to the second question.

如果我们最初有两个没有重叠变量的变量组名称,我们如何确保添加一个新重叠的变量名称到一个组不会取代原来预期的变量的使用?

if we initially have two variable groups without overlapping variable names, how do we ensure that adding a newly-overlapping variable name to a group doesn't replace use of the variable as originally intended?

确实,Azure devops目前还没有这样的功能或机制来智能检测不同变量组是否具有相同的变量名,并给出提示.

Indeed, Azure devops currently does not have such a function or mechanism to intelligently detect whether different variable groups have the same variable name, and give a prompt.

我认为这是一个合理的要求,我将您对此功能的要求添加到我们的 UserVoice 网站上,这是我们产品建议的主要论坛:

I think this is a reasonable request, I add your request for this feature on our UserVoice site which is our main forum for product suggestions:

检测变量组中相同变量的能力

作为解决方法,最简单最直接的方法是在库选项卡中打开管道链接的变量组,然后直接 ctrl + F 搜索是否存在同一个变量.

As workaround, the simplest and most direct way is that open the variable group of your pipeline link in the Library tab, and directly ctrl + F to search for the existence of the same variable.

另一种方法是使用 REST API Variablegroups - Get Variable Groups By Id 获取所有变量,然后循环比较我们要输入的变量是否相同变量存在.

Another way is to use REST API Variablegroups - Get Variable Groups By Id to get all the variables, then the loop compares with the variable we are going to enter whether the same variable exists.

这篇关于解决多个变量组中的 Azure YAML Pipeline 重叠变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆