简体   繁体   English

无法从阶段变量组设置环境名称

[英]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:我的问题是:

  1. Am I doing it wrong, or what is the reason for this behaviour?我做错了吗,或者这种行为的原因是什么?
  2. How can I tell whether variable needs to be defined at stage or pipeline level?我如何判断变量是否需要在阶段或管道级别定义?
  - 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.

相关问题 AWS API 网关 - 从 URI 中删除阶段名称 - AWS API Gateway - Remove Stage Name From URI 多阶段构建无法从前一阶段运行 ENTRYPOINT - 没有这样的文件或目录 - Multi-stage build cannot run ENTRYPOINT from previous stage - no such file or directory AWS CDK - 从资源的逻辑 ID 中排除阶段名称 - AWS CDK - Exclude stage name from logical ID of resource 在 Dockerfile 或通过 terraform 设置 $_HANDLER 环境变量 AWS Lambda - Set $_HANDLER environment variable AWS Lambda in Dockerfile or via terraform 如何在 Azure DevOps Pipeline 中设置和读取用户环境变量? - How to set and read user environment variable in Azure DevOps Pipeline? 升级到最新版本后,在 serverless.yml 文件中从 env 变量设置服务名称时遇到问题 - Facing problem to set service name from env variable in serverless.yml file after upgrading to latest version 如何使用 azure 管道变量为我的 docker 图像设置环境变量? - How to set environment variable for my docker image using azure pipeline variable? 环境变量从 golang 库中的 function 返回一个空字符串 - Environment variable returns an empty string from a function in golang library 从无服务器框架添加环境变量 lambda function - Add environment variable in lambda function from serverless framework 根据另一个环境变量设置 Google Cloud Run 环境变量值 - Set Google Cloud Run environment variables value based on another environment variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM