简体   繁体   English

Azure DevOps:用变量替换变量

[英]Azure DevOps: Substitute variables with variables

I have Azure key vault , where in I have set of keys written我有Azure key vault ,其中我有一组密钥

dev-key
stg-key
prd-key

Now I have downloaded the key dev-key in azure DevOps pipeline .现在我已经在azure DevOps pipeline中下载了密钥dev-key I want to map the downloaded variable to the 'constant' variable called 'key' , as this variable is being used in deployment yaml files(I am replacing this variable in token replace step)我想将下载的变量 map 到名为'key'的 'constant' 变量中,因为此变量正在部署 yaml 文件中使用(我在令牌替换步骤中替换此变量)

Currently I am mapping this variable in pipeline variables like,目前我正在将此变量映射到管道变量中,例如,

tenant: dev
key: $($(tenant)-key)

However the value is set in deployment yaml file to the key is $(dev-key) .但是,该值是在部署 yaml 文件中设置的,密钥为$(dev-key) Can we substitute variables with variables in Azure DevOps ?我们可以用Azure DevOps中的变量替换变量吗?

Resolving of nested variables is currently not supported.当前不支持解析嵌套变量。

See: https://developercommunity.visualstudio.com/content/problem/479258/nested-release-variables-fail-to-be-recognized.html请参阅: https://developercommunity.visualstudio.com/content/problem/479258/nested-release-variables-fail-to-be-recognized.html

An alternate solution is the following setup:另一种解决方案是以下设置:

  • Have a Key Vault per environment每个环境都有一个Key Vault
  • Have a Stage per environment每个环境都有一个Stage
  • Key names are always the same in each Key Vault每个Key Vault中的密钥名称始终相同
  • Link each vault into a variable group将每个保管库链接到一个变量组
  • Link each variable group into your pipeline and assign a Scope将每个变量组链接到您的管道并分配Scope
  • In each task(s) of a Stage access the variable as declared in the Variable groupStage的每个任务中访问Variable group

With this configuration, you can re-use the same secret key in tasks and the actual values are resolved by the scope of the variable group per Stage as you define.使用此配置,您可以在任务中重复使用相同的密钥,实际值由您定义的每个Stage的变量组的 scope 解析。

I have managed this with assigning the scope to the variables.我通过将 scope 分配给变量来解决这个问题。

variable     value              scope
key         $(dev-key)           dev
key         $(stg-key)           stg
key         $(prd-key)           prd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM