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

标签 azure azure-devops azure-cosmosdb

我正在创建一个 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/

相关文章:

azure - 通过 ARM 模板将现有混合连接添加到 Azure 应用程序服务计划

c# - Azure DevOps YAML 管道失败并显示 "A sequence was not expected"

CosmosDB 更改源上的 Azure V1 功能会在发布时触发所有更改

azure - Spring Boot Cosmos DB 实现中的动态查询

sql - Azure 备份数据库(sql 转储文件)

python - Azure Web作业导入错误: No module named email_validator

rest - 无法使用 REST API 和curl 从 Azure 文件存储检索文件列表

azure-devops - 在 Visual Studio Team Services 中为不同的自定义状态添加原因

azure-devops - 在 Azure DevOps Pipelines 中分配 AWS Cloudformation 输出变量

azure - 如何在 Cosmos DB 中选择数值字段?