从构建代理上的 docker 图像 运行 连接到 Azure Artifacts Feed
Connect to Azure Artifacts Feed from docker image running on build agent
我的 azure-pipelines.yml 文件
jobs:
- job: linux_bionic
displayName: 'Linux (Bionic)'
pool:
vmImage: 'Ubuntu 16.04'
steps:
- template: ci/docker.yml
parameters:
imageName: 'microsoft/dotnet:2.1-sdk-bionic'
environmentVariables: |
BUILD_CONFIG=Release
我的ci/docker.yml
steps:
- bash: chmod 755 ./ci/*.sh
displayName: 'Ensure build script permissions'
- task: docker@0
displayName: Build
inputs:
action: 'Run an image'
imageName: ${{ parameters.imageName }}
volumes: |
$(Build.SourcesDirectory):/src
$(Build.BinariesDirectory):/build
envVars: ${{ parameters.environmentVariables }}
workDir: '/src'
containerCommand: '/src/ci/build.sh'
detached: false
在我的 build.sh 中我有 dotnet build
命令 应该从 nuget.org 以及我的私人 azure 工件提要
恢复包
<add key="MyFeed"
value="https://pkgs.dev.azure.com/MyOrg/_packaging/MyFeed/nuget/v3/index.json" />
这是 Azure 管道日志的一部分
Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /src/src/MyProj/MyProj.csproj...
/usr/share/dotnet/sdk/2.1.402/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/MyOrg/_packaging/MyFeed/nuget/v3/index.json. [/src/MyProj.sln]
/usr/share/dotnet/sdk/2.1.402/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyProj.sln]
Build FAILED.
我认为可以在 nuget.config 中添加提要的 api 键,我在我的全局 nuget.config 中有它,但我不想在源代码管理中检查它.
有没有什么方法可以让在 docker 图像中访问提要,就像在构建代理中访问它一样?
您可以在容器中使用 Azure Artifacts Credential Provider 以及 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
环境变量来传递构建的访问令牌。
您可以使用端点凭据。
使用个人访问令牌验证访问权限:https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
RUN apt-get update && apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && dpkg-reconfigure --frontend=noninteractive locales && update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS {\"endpointCredentials\": [{\"endpoint\":\"YOUR_FEED_URL/nuget/v3/index.json\", \"username\":\"YOUR_USER\", \"password\":\"YOUR_PAT\"}]}
WORKDIR /myapp
#Copy everything else and build
COPY . .
RUN dotnet restore -s YOUR_FEED_URL/nuget/v3/index.json -nowarn:msb3202,nu1503
我的 azure-pipelines.yml 文件
jobs:
- job: linux_bionic
displayName: 'Linux (Bionic)'
pool:
vmImage: 'Ubuntu 16.04'
steps:
- template: ci/docker.yml
parameters:
imageName: 'microsoft/dotnet:2.1-sdk-bionic'
environmentVariables: |
BUILD_CONFIG=Release
我的ci/docker.yml
steps:
- bash: chmod 755 ./ci/*.sh
displayName: 'Ensure build script permissions'
- task: docker@0
displayName: Build
inputs:
action: 'Run an image'
imageName: ${{ parameters.imageName }}
volumes: |
$(Build.SourcesDirectory):/src
$(Build.BinariesDirectory):/build
envVars: ${{ parameters.environmentVariables }}
workDir: '/src'
containerCommand: '/src/ci/build.sh'
detached: false
在我的 build.sh 中我有 dotnet build
命令 应该从 nuget.org 以及我的私人 azure 工件提要
<add key="MyFeed"
value="https://pkgs.dev.azure.com/MyOrg/_packaging/MyFeed/nuget/v3/index.json" />
这是 Azure 管道日志的一部分
Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restoring packages for /src/src/MyProj/MyProj.csproj...
/usr/share/dotnet/sdk/2.1.402/NuGet.targets(114,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/MyOrg/_packaging/MyFeed/nuget/v3/index.json. [/src/MyProj.sln]
/usr/share/dotnet/sdk/2.1.402/NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyProj.sln]
Build FAILED.
我认为可以在 nuget.config 中添加提要的 api 键,我在我的全局 nuget.config 中有它,但我不想在源代码管理中检查它.
有没有什么方法可以让在 docker 图像中访问提要,就像在构建代理中访问它一样?
您可以在容器中使用 Azure Artifacts Credential Provider 以及 VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
环境变量来传递构建的访问令牌。
您可以使用端点凭据。 使用个人访问令牌验证访问权限:https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
RUN apt-get update && apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && dpkg-reconfigure --frontend=noninteractive locales && update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
RUN wget -qO- https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS {\"endpointCredentials\": [{\"endpoint\":\"YOUR_FEED_URL/nuget/v3/index.json\", \"username\":\"YOUR_USER\", \"password\":\"YOUR_PAT\"}]}
WORKDIR /myapp
#Copy everything else and build
COPY . .
RUN dotnet restore -s YOUR_FEED_URL/nuget/v3/index.json -nowarn:msb3202,nu1503