[英]Environment name cannot be set from stage variable group
I have a deployment job that refers to environment
.我有一个涉及
environment
部署工作。 I want to set this environment name with a variable from a variable group.我想用变量组中的变量设置此环境名称。
The issue is, it does not expand the name when I put then variable group at the stage (or job) level.问题是,当我将 then 变量组放在阶段(或作业)级别时,它不会扩展名称。 However it works fine when I put the variable group at the pipeline level.
但是,当我将变量组置于管道级别时,它工作正常。
My questions are:我的问题是:
- stage: Web_STG
variables:
- group: StageEnv # if the Web.EnvironmentName variable is defined here it does not work
...
- deployment: DeployWeb_STG
environment:
name: $(Web.EnvironmentName.Stg) # only works if variable group is linked at pipeline level
resourceType: VirtualMachine
So a couple of thoughts here.所以这里有几个想法。 First is there a reason you are using a variable group over a variable YAML template?
首先,您在变量 YAML 模板上使用变量组是否有原因? If there are secrets then a group is the preferred way;
如果有秘密,那么一个小组是首选方式; however, if it is static text a variable YAML template could make more sense since all the values will be under Source Control.
但是,如果它是 static 文本,变量 YAML 模板可能更有意义,因为所有值都将在源代码管理下。 To learn more here is a MS blog post on this very topic with variable templates and environments .
要了解更多信息,请参阅关于这个主题的 MS 博客文章,其中包含可变模板和环境。
Also you are defining the variable at the Macro level right before the task runs.您还在任务运行之前在宏级别定义变量。 I would recommend using it as a template expression via
${{ variables.Web.EnvironmentName.Stg }}
This would ensure expansion when the pipeline is expanded.我建议通过
${{ variables.Web.EnvironmentName.Stg }}
将其用作模板表达式,这将确保在扩展管道时进行扩展。
For your second question variables have a defined scope at the pipeline, stage, or job.对于您的第二个问题,变量在管道、阶段或作业中定义了 scope 。 This is a security feature as think each job could be dispatched to a separate agent.
这是一项安全功能,因为认为每个作业都可以分派给单独的代理。 As such Pipeline jobs that only need access to say a dev secret will have these values only available if the deployment job has the variables scoped correctly.
因此,只需要访问开发秘密的流水线作业只有在部署作业的变量范围正确时才具有这些值。
An additional troubleshooting step you can take is to download the expanded-pipeline.yml file form the logs.您可以采取的另一个故障排除步骤是从日志中下载 expanded-pipeline.yml 文件。 This will show the full variable expansion that is occurring to confirm if you are getting the correct variable population you are expecting.
这将显示正在发生的完整变量扩展,以确认您是否获得了您期望的正确变量总体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.