点击上方蓝字关注“汪宇杰博客”
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/af3ec684f8631388406118c901faf6a9.png)
今天我在为一个从TFVC迁移到Git的老项目重新配置发布到Azure App Service的CI/CD管线的时候,Azure DevOps竟然爆了。这是一个微软已知的bug,目前还未修复,我来带大家看看如何手工workaround这个问题。
首先,部署的时候报错消息如下:
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/29179d55ae9f38a57a8ee5628a8dab48.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](https://img-blog.csdnimg.cn/img_convert/e7c198f014e02196cf135140f5dafda8.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](https://img-blog.csdnimg.cn/img_convert/f9e9752d76e4d8d3a1199384bf86d453.png)
指定一个 Name,如 ediwang-AzureDevOps
选择 "Accounts in this organizational directory only"
Redirection URL 填: https://VisualStudio/SPN
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/557f50aba645be3ef2f3f6a2822e51c7.png)
Description 任意,Expires 建议选 Never
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/e3af82f9df86b175f2c79745ed97a744.png)
然后把 Client Secrets 里的密钥复制出来
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/789367e14be9a8e79fd2957237fff038.png)
还有Overview 里的 Application (client) ID 以及 Directory (tenant) ID
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/1ddfcd73e281fda5f6391745e20e6ce0.png)
然后到 Subscription > Access control (IAM) 里搜索刚才创建的App名字,搜到以后,Add a role assignment
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/f6163094d1b13c9762003b276408f24a.png)
然后安排一个 Owner,Azure这边就搞定了!
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/abdc51c2fca0d2daed475347d637902b.png)
然后回到 Azure DevOps
在 Azure App Service Deploy 的任务里点 Manage
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/64294a2d9fe222953b1f4d8db7ce3732.png)
在 Service Connections 里添加一个 Azure Resource Manager
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/d5a20526b67d58a45471843ae04df4f8.png)
然后点“use the full version of the service connection dialog.”
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/8cdc7db3ff3ac636eb5fe0915d2e29a8.png)
选择和输入对应的值。其中 Service pricipal client ID 就是刚才复制的 Application (client) ID,Service pricipal key 就是刚才 Client Secrets 里复制的 VALUE
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/a34db7ea1d1d70b17ba65fe525d50b46.png)
最后点击 Verify connection,不成功便成仁!
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/5b8d0a5f0dc354d95101119877ee22aa.png)
到此为止,就全部搞定了。重新回到你的部署任务里,就能成功选择目标Azure App Service上的网站了,并且能部署成功。
![640?wx_fmt=png](https://img-blog.csdnimg.cn/img_convert/59a354e74d2232eb3bafc7b43c6eb4cc.png)
真是不容易……