gpt4 book ai didi

azure - 使用 Azure cli/PowerShell 获取 Cosmos DB 帐户主帐户 key /主连接字符串

转载 作者:行者123 更新时间:2023-12-03 03:46:07 26 4
gpt4 key购买 nike

我正在创建一个 Azure DevOps 发布管道,我想在其中获取 cosmos db 帐户的主帐户 key /主连接字符串作为 Azue CLI 任务的一部分,并将其发布为任务变量,以便我可以使用它作为数据工厂 ARM 部署事件的参数,该事件是同一管道中的后续任务。我用来获取 key 的代码是:

az cosmosdb keys list \
--name <db_account_name> \
--resource-group <resource_group_name> \
--subscription <subscription_name> \
--type connection-strings \
--query 'connectionStrings[0].connectionString' \
--output tsv

代码返回

AccountEndpoint=https://<db_account_name>.documents.azure.com:443/;AccountKey=***;

但它不显示帐户 key 内的字符串内容。

当我将其存储为任务变量并将其用于 ARM 任务时,出现错误。

  1. 如何通过属于 azure devops 管道一部分的 Azure cli/任务获取 cosmos db 帐户主连接字符串/帐户 key 的文本内容?
  2. 我是否需要更改用于从 Azure 管道访问 cosmos db 帐户的配置文件的 RBAC 角色?

最佳答案

how to get the text content of the cosmos db account primary connection string/account key through azure cli/tasks that are part of azure devops pipeline?

我无法重现您的问题,它在我这边工作正常,AccountKey 以纯文本形式输出。

我的内联脚本:

$a = az cosmosdb keys list --name joycosmostest --resource-group <groupname> --subscription <subscription-id> --type connection-strings --query 'connectionStrings[0].connectionString' --output tsv

echo "##vso[task.setvariable variable=connectionString;isOutput=true]$a"

enter image description here

enter image description here

do I need to change the RBAC roles for the profile that I use to access cosmos db account from azure pipeline?

在 Azure CLI 任务中,它使用 Azure 资源管理器服务连接来验证 Azure 服务,因此您应该确保服务连接中使用的服务主体在您的 cosmos db 帐户中具有正确的 RBAC 角色,例如Contributor .

关于azure - 使用 Azure cli/PowerShell 获取 Cosmos DB 帐户主帐户 key /主连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69127444/

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