手工修复Azure DevOps无法连接到Azure的问题

点击上方蓝字关注“汪宇杰博客”

640?wx_fmt=png

今天我在为一个从TFVC迁移到Git的老项目重新配置发布到Azure App Service的CI/CD管线的时候,Azure DevOps竟然爆了。这是一个微软已知的bug,目前还未修复,我来带大家看看如何手工workaround这个问题。

首先,部署的时候报错消息如下:

640?wx_fmt=png

Failed to get resource ID for resource type 'Microsoft.Web/Sites' and resourcename 'moonglade'. Error: Could not fetch access token for Managed ServicePrincipal. Please configure Managed Service Identity (MSI) for virtual machine'https://aka.ms/azure-msi-docs'.Status code: 400, status message: Bad Request

本质上是因为Azure DevOps到Azure的连接无效,或者过期了。但是当我尝试重新认证的时候,竟然又爆了:

TF14045: The identity with type 'Microsoft.IdentityModel.Claims.ClaimsIdentity' could not be found.

640?wx_fmt=png

对此,微软有个已知bug可以追踪:https://developercommunity.visualstudio.com/content/problem/412380/tf14045-the-identity-with-type-microsoftidentitymo-1.html

解决方法

进入 Azure Active Directory > App registrations (Preview)

点击 "+ New registration"

640?wx_fmt=png

指定一个 Name,如 ediwang-AzureDevOps

选择 "Accounts in this organizational directory only"

Redirection URL 填: https://VisualStudio/SPN

640?wx_fmt=png

Description 任意,Expires 建议选 Never

640?wx_fmt=png

然后把 Client Secrets 里的密钥复制出来

640?wx_fmt=png

还有Overview 里的 Application (client) ID 以及 Directory (tenant) ID

640?wx_fmt=png

然后到 Subscription > Access control (IAM) 里搜索刚才创建的App名字,搜到以后,Add a role assignment

640?wx_fmt=png

然后安排一个 Owner,Azure这边就搞定了!

640?wx_fmt=png

然后回到 Azure DevOps

Azure App Service Deploy 的任务里点 Manage 

640?wx_fmt=png

Service Connections 里添加一个 Azure Resource Manager

640?wx_fmt=png

然后点“use the full version of the service connection dialog.

640?wx_fmt=png

选择和输入对应的值。其中 Service pricipal client ID 就是刚才复制的 Application (client) IDService pricipal key 就是刚才 Client Secrets 里复制的 VALUE

640?wx_fmt=png

最后点击 Verify connection,不成功便成仁!

640?wx_fmt=png

到此为止,就全部搞定了。重新回到你的部署任务里,就能成功选择目标Azure App Service上的网站了,并且能部署成功。

640?wx_fmt=png

真是不容易……

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值