从 azure Devops 管道更新变量组

问题描述 投票:0回答:1

我正在尝试使用管道中的

az pipelines
cli 更新变量组中的变量,我创建了一个 PAT 并将其传递到管道,其工作正常。但我使用默认的,例如
$(System.AccessToken)
它能够列出变量组中的变量,但无法更新变量组。 其言

错误:您无权在 变量组。变量组管理员应将您添加到 管理员角色。 ##[错误]脚本失败,退出代码:1

经过一番搜索,我发现我需要在变量组中添加Project Collection Build Service(name)作为管理员,然后重试。我已经添加了这一点,但我仍然遇到同样的错误。有什么建议吗?

我使用的是经典管道,这是从管道导出的任务。

steps
- task: AzureCLI@2
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: 'sc'
    scriptType: pscore
    scriptLocation: inlineScript
    inlineScript: |
     az extension add --name azure-devops
     az pipelines variable-group variable list --group-id id --org "orgname" --project "projectname"
     az pipelines variable-group variable update --group-id id --name apim-service-name --value $(str_tf_module_containername) --org "orgname" --project "projectname"
  env:
    AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)
azure azure-devops azure-pipelines azure-cli azure-pipelines-yaml
1个回答
5
投票

这个效果很好:

steps
- pwsh: |
     az extension add --name azure-devops
     az pipelines variable-group variable list --group-id id --org "orgname" --project "projectname"
     az pipelines variable-group variable update --group-id id --name apim-service-name --value $(str_tf_module_containername) --org "orgname" --project "projectname"
  env:
    AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

但是您需要授予

Project Collection Build Service (account)
给定变量组的管理员权限:

© www.soinside.com 2019 - 2024. All rights reserved.