在 azure devops 中构建 Docker 镜像时如何传递 PAT 令牌?

问题描述

Net 核心项目。我在 azure artifact 中有一些 nuget 包。在 Dockerfile 中,我尝试使用它们,如下所示。

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /app
ENV ASPNETCORE_URLS=http://+:80  
EXPOSE 80

# The Personal Access Token arg
ARG PAT

# Set environment variables
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS '{"endpointCredentials":[{"endpoint":"https://myorg.pkgs.visualstudio.com/1234-c281-4ddc-952e-83e5a37a1c66/_packaging/mybusiness/nuget/v3/index.json","username":"USERNAME","password":"'${PAT}'"}]}'

# Get and install the Artifact Credential provider
RUN wget -O - https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh  | bash


COPY mybusiness.sln ./

COPY mybusiness/*.csproj ./mybusiness/

RUN dotnet restore -s "https://mybusiness.pkgs.visualstudio.com/123-c281-4ddc-952e-83e5a37a1c66/_packaging/mybusiness/nuget/v3/index.json" -s "https://api.nuget.org/v3/index.json"


COPY mybusiness/. ./mybusiness/


RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app
COPY --from=build /app/out ./

ENTRYPOINT ["dotnet","mybusiness.dll"]

下面是我要构建的 Yaml

 - task: NuGetAuthenticate@0
 
    - task: Docker@1
      displayName: Build an image
      continueOnError: true
      condition: and(succeeded(),eq(variables['Build.SourceBranch'],'refs/heads/master'))
      inputs:
        containerregistrytype: 'Azure Container Registry'
        azureSubscriptionEndpoint: 'DevOps_on_rg_contributor'
        azureContainerRegistry: 'acr.azurecr.io'
        command: 'build'
        dockerFile: 'src/app/Dockerfile'
        arguments: '--build-arg PAT=$(System.AccessToken)'
        imageName: '$(Build.Repository.Name):$(Build.BuildId)'

这给了我以下错误 Response status code does not indicate success: 401 (Unauthorized).

我无法在这里确定根本原因。只是担心我是否传递了正确的 PAT 令牌? Cansomeone 帮助我确定问题。任何帮助,将不胜感激。谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)