变量yaml中的变量是变量名称

发布于 2025-02-07 20:22:03 字数 1122 浏览 3 评论 0原文

我在管道中有以下任务(Azure DevOps)。第一个任务使用变量$(mySecretName)从密钥维护中读取秘密,哪个值是secret> secret-name。第二个任务需要将读取秘密的价值传递给ARM:

- task: AzureKeyVault@2
  displayName: 'Read secret'
  inputs:
     azureSubscription: $(mySubscription)
     KeyVaultName: $(myKeyVault)
     SecretsFilter: $(mySecretName)
     RunAsPreJob: false

- task: AzureResourceGroupDeployment@3
  displayName: 'Use secret value'
  inputs:
     resourceGroupName: $(myResourceGroup)
     location: $(myLocation)
     azureResourceManagerConnection: $(mySubscription)
     templateLocation: 'Linked artifact'
     csmFile: '$(Pipeline.Workspace)/cd-template.json'
     overrideParameters: >
        -secretValue "$($(mySecretName))"
     deploymentMode: 'Incremental'

in Line -secretValue“ $($(mySecretName))”我试图以这种方式解决,但显然它不起作用:$(mySecretName) - > $(secret -name) - > 秘密值。如果我使用$(秘密名称)它将起作用,但是我需要使用$(mySecretName),因为该名称会根据环境而更改。

是否有任何解决方案可以使我获得变量的值哪个名称是另一个变量的值?

I have following tasks in a pipeline (Azure DevOps). First task read a secret from a KeyVault using a variable $(mySecretName) which value is secret-name. Second task needs to pass the value of the read secret to a ARM:

- task: AzureKeyVault@2
  displayName: 'Read secret'
  inputs:
     azureSubscription: $(mySubscription)
     KeyVaultName: $(myKeyVault)
     SecretsFilter: $(mySecretName)
     RunAsPreJob: false

- task: AzureResourceGroupDeployment@3
  displayName: 'Use secret value'
  inputs:
     resourceGroupName: $(myResourceGroup)
     location: $(myLocation)
     azureResourceManagerConnection: $(mySubscription)
     templateLocation: 'Linked artifact'
     csmFile: '$(Pipeline.Workspace)/cd-template.json'
     overrideParameters: >
        -secretValue "$($(mySecretName))"
     deploymentMode: 'Incremental'

In line -secretValue "$($(mySecretName))" I'm trying to resolve in this way but apparently it does not work: $(mySecretName) -> $(secret-name) -> secret value. If I use $(secret-name) it will work, but I need to use $(mySecretName) because the name will change depending on the environment.

Is there any solution that allows me to get the value of a variable which name is the value of another variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁的年少不轻狂 2025-02-14 20:22:03

从您的yaml示例中,您使用的是嵌套变量$($(mySecretName))。该管道中尚未支持它。

要达到您的要求,您可以使用扩展名来使用可变设置的任务:可变工具箱

您可以在AzureresourceGroupDeployment任务之前添加变量设置任务。

例如:

steps
- task: VariableSetTask@2
  displayName: 'Set variable: kevin to: ''$($(test))'''
  inputs:
    variableName: NewVariable
    Value: '$($(mySecretName))'

- task: AzureResourceGroupDeployment@3
  displayName: 'Use secret value'
  inputs:
     resourceGroupName: $(myResourceGroup)
     location: $(myLocation)
     azureResourceManagerConnection: $(mySubscription)
     templateLocation: 'Linked artifact'
     csmFile: '$(Pipeline.Workspace)/cd-template.json'
     overrideParameters: >
        -secretValue "$(NewVariable)"
     deploymentMode: 'Incremental'

From your YAML sample, you are using nested variables $($(mySecretName)). It is not yet supported in the pipelines.

To achieve your requirement, you can use the Variable Set task from extension: Variable Toolbox.

You can add the Variable Set task before the AzureResourceGroupDeployment task.

For example:

steps
- task: VariableSetTask@2
  displayName: 'Set variable: kevin to: ''$($(test))'''
  inputs:
    variableName: NewVariable
    Value: '$($(mySecretName))'

- task: AzureResourceGroupDeployment@3
  displayName: 'Use secret value'
  inputs:
     resourceGroupName: $(myResourceGroup)
     location: $(myLocation)
     azureResourceManagerConnection: $(mySubscription)
     templateLocation: 'Linked artifact'
     csmFile: '$(Pipeline.Workspace)/cd-template.json'
     overrideParameters: >
        -secretValue "$(NewVariable)"
     deploymentMode: 'Incremental'
送舟行 2025-02-14 20:22:03

您可能无法使用嵌套变量,但是可以在变量中嵌套a parameter 。因此,如果将mySecretName作为参数传递,则可以执行此操作:

${{ parameters.mySecretName }}

SecretsFilter: $(${{ parameters.mySecretName }})

这显然是因为前处理器在执行前替换了参数值。

You may not be able to use nested variables, but you can nest a parameter in a variable. Thus, if you pass mySecretName as a parameter, you can do this:

${{ parameters.mySecretName }}

SecretsFilter: $(${{ parameters.mySecretName }})

This is apparently because a pre-processor substitutes the parameter value before execution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文