Unable to pull packages from GitHub packages in a build

I have a build that is using a .NET Restore step to pull NuGet packages from GitHub Packages. Previously these builds were pulling from the TC NuGet feed and worked without any issues.

I have configured a PAT in GitHub that has read/write access to GitHub packages for my organization and is being used to pull NuGet packages from GitHub in other projects, but for some reason in this project I keep getting an authentication error, and I am unsure if I have configured something in TeamCity incorrectly.

What I have configured in TeamCity project in order to pull packages from GitHub packages:

1. Configured a NuGet feed for GitHub with my GitHub PAT in the Build Features of the project. This PAT has permissions to manage (read and write) packages and is used in other projects that are pulling from this feed. The feed URL is https://nuget.pkg.github.com/MyOrg/index.json.

2. Configured the DotNet Restore step in the project to list https://nuget.pkg.github.com/MyOrg/index.json as a NuGet package source in the “NuGet package sources” box.

When I run a build, I receive the following errors in the build log (note the URLs referenced, which are not the same as the GitHub feed URL):

---------------------------

[19:36:18]Step 2/8: DotNet Restore (.NET) (8s)

[19:36:18][Step 2/8] dotnet --version

[19:36:18][Step 2/8] Starting: Getting the .NET SDK version /home/admin/.dotnet/ dotnet --version

[19:36:18][Step 2/8] in directory: /home/admin/BuildAgent/work/152c8fd6f6227818

[19:36:18][Step 2/8] 8.0.100

[19:36:18][Step 2/8] Process exited with code 0

[19:36:18][Step 2/8] dotnet restore (8s)

[19:36:18][dotnet restore] Starting: .NET SDK 8.0.100 /home/admin/.dotnet/dotnet restore /home/admin/BuildAgent/work/152c8fd6f6227818/MyOrg.Cache.sln --source https://nuget.pkg.github.com/MyOrg/index.json --source https://api.nuget.org/v3/index.json --source https://devops.myorg.com/httpAuth/app/nuget/feed/Phoenix/Phoenix/v3/index.json @/home/admin/BuildAgent/temp/agentTmp/1.rsp

[19:36:18][dotnet restore] in directory: /home/admin/BuildAgent/work/152c8fd6f6227818

[19:36:19][dotnet restore] Determining projects to restore...

[19:36:20][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:20][dotnet restore] Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:20][dotnet restore] Response status code does not indicate success: 401 (Unauthorized).

[19:36:21][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:21][dotnet restore] Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:21][dotnet restore] Response status code does not indicate success: 401 (Unauthorized).

[19:36:23][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:23][dotnet restore] Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:23][dotnet restore] Response status code does not indicate success: 401 (Unauthorized).

[19:36:24][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:24][dotnet restore] Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:24][dotnet restore] Response status code does not indicate success: 401 (Unauthorized).

[19:36:25][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:25][dotnet restore] Retrying 'FindPackagesByIdAsync' for source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:25][dotnet restore] Response status code does not indicate success: 401 (Unauthorized).

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/BuildAgent/work/152c8fd6f6227818/MyOrg.Cache/MyOrg.Cache.csproj : error NU1301: Failed to retrieve information about 'MyOrg.AddressService.Models' from remote source 'https://nuget.pkg.github.com/MyOrg/download/MyOrg.addressservice.models/index.json'.

[19:36:26][dotnet restore] Failed to restore /home/admin/BuildAgent/work/152c8fd6f6227818/MyOrg.Cache/MyOrg.Cache.csproj (in 6.64 sec).

[19:36:26][dotnet restore]

[19:36:26][dotnet restore] Build FAILED.

[19:36:26][dotnet restore]

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] /home/admin/.dotnet/sdk/8.0.100/NuGet.targets(156,5): warning : Your request could not be authenticated by the GitHub Packages service. Please ensure your access token is valid and has the appropriate scopes configured.

[19:36:26][dotnet restore] 6 Warning(s)

[19:36:26][dotnet restore] 1 Error(s)

[19:36:26][dotnet restore]

[19:36:26][dotnet restore] Time Elapsed 00:00:07.78

[19:36:26][dotnet restore] Process exited with code 1

[19:36:26][Step 2/8] Step DotNet Restore (.NET) failed

-------------

While it seems like a GitHub issue, this PAT is working in other projects, so I'm wondering if there is some other configuration element that I have forgotten to add in my TeamCity project?  Is there any significance in that the URLs mentioned in the log are different than the configured NuGet feed URL? If I manually enter one of the download URLs outlined in the build log I am prompted for credentials. If I enter my GitHub user and PAT, I am able to see all of the versions of the package that have been uploaded, so it seems the credentials are valid. I'm not sure what else to change or configure here.

0
1 comment
For public reference, we handled this internally. The issue seems to be that the nuget feed credentials are not being passed correctly on this project, or that the project or machine are overwriting them in some way, we are still in the process of clearing what's going on exactly, but as a workaround provided by Neil, setting the credentials on the nuget configuration directly works.
1

Please sign in to leave a comment.