我正在使用 Azure DevOps Pipeline。
我在 Azure Devops 中创建了一个 ServiceConnection 并在其中添加了一个服务主体。
我使用的代理是“ubuntu-latest”
我在管道中创建了一个 powershell 任务
- task: AzureCLI@2
displayName: 'Assign Role'
name: task_inline
inputs:
scriptType: 'pscore'
azureSubscription: 'AzureConnRM'
scriptLocation: scriptPath
addSpnToEnvironment: true
scriptPath: './abc.ps1'
在 Powershell 中更新现有的 RBAC 角色,我运行以下命令:
az role assignment update --role-assignment $myjson --debug --verbose
我传递的 json 是
$myjson = '{
"conditionVersion": "",
"roleDefinitionName": "Contributor",
"principalType": "User",
"condition": "",
"id": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/resourceGroups/Trial-RG/providers/Microsoft.Authorization/roleAssignments/45d7dc3c-4a95-8a1c-bd87-f8a460c6d255",
"resourceGroup": "Trial-RG",
"roleDefinitionId": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c",
"type": "Microsoft.Authorization/roleAssignments",
"scope": "/subscriptions/097ca710-067e-4a70-8ce6-494268568148/resourceGroups/Trial-RG",
"principalId": "8cd5df22-42f4-405e-b3ab-d562eaf1da92",
"canDelegate": "",
"description": "Updated",
"name": "45d7dc3c-4a95-8a1c-bd87-f8a460c6d255"
}'
但出现错误:
错误详细信息:需要用双引号括起来的属性名称:第 2 行第 3 列(字符 4)
最佳答案
谢谢@Toni --debug 帮助我查看详细日志。 3 个字段 conditionVersion、canDelegate、condition 未正确设置。我从 json 中删除了这些属性,它起作用了。
关于azure - 无法使用 Azure DevOps Pipeline 更新 RBAC 角色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73870272/