无法在 Azure DevOps(Release Pipeline)中获取 Azure Container Registry 的服务连接

Unable to get the service connection for Azure Container Registry in Azure DevOps (Release Pipeline)

我正在尝试通过 Azure DevOps 服务在 Azure 应用服务上部署 docker 容器。我已将 docker 图像推送到 Azure 容器注册表。当我尝试创建发布定义时,找不到 Azure 容器注册表的服务连接。我已经为 ACR 创建了服务连接,但它没有显示在 Azure DevOps 门户的列表中。

当我选择 'Azure Container Repository' 作为源类型时,服务连接在下拉框中不可见。我正在使用 DockerHub 作为另一种选择。它在列表中显示服务连接。

我为 ACR 创建服务连接所遵循的步骤:

  1. 已从列表中选择 Docker 注册表
  2. 选择 Azure 容器注册表 作为注册表类型。提供了来自 ACR 的订阅 ID 和注册表。
  3. 提供服务连接名称并保存。

UPDATE

我已经通过提供订阅 ID 和租户 ID 使用托管身份验证为 Azure 资源管理器创建了服务连接。我正在尝试在 Artifact 设置中使用此连接。我收到以下错误。

无法为给定的服务连接找到名称为 endpoint.serviceprincipalid 的变量。

无法从 ACR 中提取 docker 图像。应用服务的日志显示存储库的拉取访问被拒绝。

Service Connection problem solved but facing docker permission issue from App service

2020-02-10 12:31:11.781 INFO  - Pulling image from Docker hub: 
kbdockerregis/kbdockerimage:15

2020-02-10 12:31:14.406 ERROR - DockerApiException: Docker API responded with 
status code=NotFound, response={"message":"pull access denied for 
kbdockerregis/kbdockerimage, repository does not exist or may require 'docker 
login': denied: requested access to the resource is denied"}

2020-02-10 12:31:14.408 ERROR - Image pull failed: Verify docker image 
configuration and credentials (if using private repository)

2020-02-10 12:31:14.412 INFO  - Stoping site kbapp1 because it failed during 
startup.

When I selected 'Azure Container Repository' as the source type, the service connection is not visible in the drop down box.

对于第一期,这是因为api当您选择ACR作为发布源时,我们使用的系统如下所示:

https://dev.azure.com/{org}/{project}/_apis/serviceendpoint/endpoints?type=azurerm

可以看到这个api附带的参数是type=azurerm。它只获取类型为 Azure Resource Manager 的服务连接。但是Container Registry不属于这个。

因此,您最好创建和使用类型为Azure Resource Manager type的服务连接。


Variable with name endpoint.serviceprincipalid could not be found for the given service connection.

对于第二个问题,没有从您那里得到太多信息(比如检查股权跟踪)。因此,根据我的了解,我建议您将类型从 Managed Identity Authentication 更改为 Service Principal Authentication。然后按照这个 doc 配置它。

这样比较安全,可以先授权。

Service Principal Client id,就是你在Azure app registrations中创建app后的application id:

服务主体密钥:


Stack overflow 是一个开放论坛,不能安全地共享一些我需要并用于从后端调查的关键信息(尤其是 Fiddler trace)。你最好去 here 因为你可以在那里选择 Microsoft Only。如果可以的话,我可以去那个社区,让那个社区的工程师给我看。这样我就可以继续深入研究了。