azure-devopsnuget-package.net-7.0personal-access-token

NU1301: Unable to load the service index for source, even after setting up Personal Access Token


Recently my Net7 build pipeline started failing with the error

NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/<mypartner>/<guid>/_packaging/mypackagename/nuget/v3/index.json

I can open the index.json in the browser in a round about manner. In that on navigating to the .json Microsoft asks me to login again. I then get a 404 error

This pkgs.dev.azure.com page cant be found
No web page was found for the web address
https://pkgs.dev.azure.com/_public/_MsalSignedIn
HTTP ERROR 404

If I then refresh I do see the .json

My Yaml is

pool:
  vmImage: 'windows-latest'
  
variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'
  ValidAuthenticationTypes_trackCommon: 'negotiate,ntlm'

steps:
- task: NuGetAuthenticate@1
  inputs:
    nuGetServiceConnections: 'trackCommon'
    forceReinstallCredentialProvider: true


- task: NuGetToolInstaller@1
  inputs:
    versionSpec: '>=6.1'
    checkLatest: false
    
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '7.x'
    includePreviewVersions: true
- script: |
    echo "##vso[task.setvariable variable=PAV_NUGET_AUTH_TOKEN]$(PAV_NUGET_AUTH_TOKEN)"
  displayName: 'Set NuGet Auth Token'
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    feedsToUse: 'config'
    nugetConfigPath: 'ApiFortrack/nuget.config'
    externalFeedCredentials: 'trackCommon'
 

The error occurs on the last task DotNetCoreCLI@2

I tried adding a Personal Access Token to the mypartner organization as per Zimmergren.net but it has not helped.

I use the same email address to login to the devops organisation that my pipeline is in and the mypartner organization. I wonder if it is relevant that I have to authenticate each time I switch between these organisations.

Update

After reading this similar question I tried replacing the problem task with

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: 'config'
    nugetConfigPath: 'ApiFortrack/nuget.config'
    externalFeedCredentials: 'trackCommon'

However the pipeline does not complete this task. After 25 minutes I cancelled and am now trying a re-run.

The log says

C:\hostedtoolcache\windows\NuGet\6.11.0\x64\nuget.exe restore D:\a\1\s\ApiFortrack3.sln -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\s\ApiFortrack\nuget.config

Update I was able to get the pipeline running by updating the PAT in the trackCommon service connection.

Now I am wondering whether adding the PAT in a variable is redundant. Also I am wondering if moving the mypartner organisation to be in the same Entre Id Tenant as my source project would remove the need for a PAT. I gather it would save the constant need to authenticate as I switch between organisations.


Solution

  • The PAT needed to be set up in the Service Connection