Reputation: 2077
So I have an Azure DevOps Pipelines that looks like this:
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?
Upvotes: 5
Views: 13240
Reputation: 1080
Create a PAT for your [email protected]
I recommend to add a variable group: feedCredentials (e.G. variables PAT as secret variable and variable USER_VARIABLE) in azure devops/organisation/project/Pipelines/Library
link this to your variables in your build.yml:
variables:
- group: feedCredentials
map this to the tasks where needed
- task: NuGetCommand@2
displayName: 'NuGet restore **/your.sln'
env:
USER_VARIABLE : $(USER_VARIABLE)
PAT : $(PAT)
inputs:
restoreSolution: '**/your.sln'
feedsToUse: 'config'
nugetConfigPath: 'Nuget.config'
don't miss the mapping in your nuget.config in your git repo in the root directory, or the specified nugetConfigPath. Like @Hugh_Lin wrote
Try your Build
Upvotes: 0
Reputation: 4427
You can also use the Windows Credential Manager, which is a significantly more secure way to store your credentials.
You can even add credentials via powershell if it's a build machine
Upvotes: -4
Reputation: 1691
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.
Upvotes: 0
Reputation: 19381
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.
Upvotes: 7