首页 > 解决方案 > 从 yaml 管道中的变量组参数化 azureSubscription

问题描述

我将 Yaml 用于 Azure devops 管道。我为此使用了分层样式。

我有一个顶级 yaml: feature.yaml,它具有以下结构:

trigger:
...
pool:
  vmImage: ...
  
variables:
  group: ...

stages:
  - template: deploy.yaml
    parameters:
      subName: $(subscription) #This should be taken from Variable group

我有 deploy.yaml 作为:

stages:
    - stage: deploy
      jobs:
        - job: deploy
          steps:
          - task: AzureKeyVault@1
            inputs:
              azureSubscription: $(paramaters.subName) #This should be resolved from parameter passed form feature.yaml
              KeyVaultName: ...
              SecretsFilter: '*'
              RunAsPreJob: true

但是,每当我从 Azure DevOps 运行它时,我都会收到此错误:

There was a resource authorization issue: "The pipeline is not valid. Job deploy: Step AzureKeyVault input ConnectedServiceName references service connection $(paramaters.subName) which could not be found. The service connection does not exist or has not been authorized for use. For authorization details, refer to https://aka.ms/yamlauthz."

似乎管道无法从变量组中解析 azureSubscription 名称的值。

有什么建议么?

标签: azureazure-devopsyamlpipelineazure-keyvault

解决方案


我发现最初解析 YAML 时,它希望变量组在范围内。我需要将我的变量组移动到 YAML 文件的顶部,然后它找到了 azure 订阅变量。不是我所期待的。


推荐阅读