How to add credential for private nuget feed into Azure DevOps Pipelines?

Viewed 1734

So I have an Azure DevOps Pipelines that looks like this:

enter image description here

So currently, with NuGet 4.6.2, I can add my credentials/PAT using service endpoint. This is working now.

But, I am stuck with NuGet 4.6.2. If I upgrade to the latest NuGet (5.8), then I will get errors during NuGet restore:

Unable to find version '<x.y.z>' of package '<my.object.package>'.
  C:\Users\VssAdministrator\.nuget\packages\: 
  Package '<my.object.package.x.y.z>' is not found on source 'C:\Users\VssAdministrator\.nuget\packages\'.
  https://api.nuget.org/v3/index.json: 
  Package '<my.object.package.x.y.z>' is not found on source 'https://<private.nuget.url>: Failed to fetch results from V2 feed at '
  Response status code does not indicate success: 401 (Unauthorized).)

My guess is that somehow I need to pass in the credential to the private NuGet feed (outside of the organization) differently - but not sure how. Or maybe I am missing something here?

3 Answers

According to the error message, we could to know it is trying to access your private nuget feed and get this 401 (Unauthorized) error. It seems you did not provide certification information in the nuget.config file.

You can try to add the certification information in your nuget.config as following:

<configuration>
  <packageSources>
    <add key="keyName" value="privateFeedUrl" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <keyName>
      <add key="Username" value="%USER_VARIABLE%" />      
      <add key="ClearTextPassword" value="%PAT%" />
    </keyName>
  </packageSourceCredentials>
</configuration>

You can refer to this thread for some more details.

Adding your credentials to the Nuget.Config should work, the only difference is that the format for the Nuget.Config file has slightly changed for the newer versions of nuget, refer to this link to see how to correctly format your nuget.config file.

You can also use the Windows Credential Manager, which would be a much more secure way to store your credentials.

Related