Search code examples
azureazure-devopsazure-pipelinesazure-pipelines-yamlazure-pipelines-tasks

Access to private feed from Azure Devops pipeline


I want to create access to my private feed from pipeline (Project A), but everytime when i try run dotnet restore to restore .net project with nugets from private feed (project scoped feed in Project B) i got

error NU1301: Unable to load the service index for source <<url_to_my_feed>>

My pipeline.yml looks like:

[previous jobs]

- task: NuGetAuthenticate@0

- task: Docker@2
  displayName: Build image
  inputs:
    command: build
    containerRegistry: $(dockerRegistryServiceConnection)
    repository: $(contentHostRepositoryName)
    Dockerfile: "$(Build.SourcesDirectory)/src/modules/content/src/Dockerfile"
    arguments: '--build-arg PAT=$(VSS_NUGET_ACCESSTOKEN)'
    tags: |
       $(tag)

[next jobs]

My dockerfile looks like:

...
ARG PAT
RUN dotnet nuget add source <<url_to_my_feed>> --name <<name>> --username <<username>> --password $PAT --store-password-in-clear-text
...

When i replace '--build-arg PAT=$(VSS_NUGET_ACCESSTOKEN)' to '--build-arg PAT=<<pat_token>>' where <<pat_token>> is token, who i generate manualty to my personal account in Azure Devops - everythink work fine.

What i try:

  • using $(System.AccessToken) instead $(VSS_NUGET_ACCESSTOKEN)
  • in feed set contribution permission to Project A Build Service
  • in project B disable Limit job authorization scope to current project for non-release pipelines and Limit job authorization scope to current project for release pipelines
  • use NuGetAuthenticate@0 and NuGetAuthenticate@1
  • into Pipelines Security in Project A allow Project Build Service for everythink
  • before using $(System.AccessToken) main into varaible

Solution

  • Add the Project Collection Build Service (Organization) and let it has related permission.

    enter image description here

    Since you use yml file pipeline, and you disable Limit job authorization scope to current project for non-release pipelines, so project build service account will change to project collection build service account.

    And please use $(System.AccessToken) to auth.