gpt4 book ai didi

azure - 有没有办法使用变量来连接到 azure 的服务?

转载 作者:行者123 更新时间:2023-12-02 05:57:27 25 4
gpt4 key购买 nike

我一直在编写一些 terraform 并使用 Azure Devops 来部署管道。但是,如果我使用变量 $(serviceconnection) 进行服务连接,则会失败并出现以下错误:

存在资源授权问题:“管道无效。作业 DeployDev:步骤 TerraformCLI1 输入 backendServiceArm 引用无法找到的服务连接 $(serviceconnection)。服务连接不存在或尚未建立授权使用。我尝试过授权但没有成功。有什么解决办法吗?

该任务是一个使用 terraform 的 YAML 任务,如下所示:

- task: charleszipp.azure-pipelines-tasks-terraform.azure-pipelines-tasks-terraform-cli.TerraformCLI@0
displayName: 'Terraform Init'
inputs:
command: init
workingDirectory: $(Agent.BuildDirectory)/a/azuredirectory/terraform
backendType: azurerm
backendServiceArm: $(serviceconnection)
backendAzureRmResourceGroupName: $(ResourceGroupName)
backendAzureRmStorageAccountName: $(StorageAccountName)
backendAzureRmContainerName: $(ContainerName)
backendAzureRmKey: $(AzureRmKey)

最佳答案

您需要使用 Template expression syntax对于服务连接变量:

backendServiceArm: ${{ variables.serviceconnection }}

我想这是因为在管道运行之前需要知道服务连接。

示例用例。使用名为 variable.dev.yaml 的变量文件:

variables:
serviceconnection: my-dev-service-connection-name
...

然后您可以在管道中引用它:

jobs:
- job: myJob
...
variables:
- template: ./variable.dev.yaml
steps:
- task: AzureCLI@2
inputs:
azureSubscription: ${{ variables.serviceconnection }}
...

关于azure - 有没有办法使用变量来连接到 azure 的服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72787368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com