(401) Unauthorized error when attempting to load packages from TeamCity Feed

I’m using TeamCity (9.1.6) with Octopus (3.3.6). As far as I can tell, nothing has changed since the last time I deployed changes to Octopus, but today no luck. I get a 401 Unauthorized error on my create release step. I get a similar error when attempting to test the TeamCity package feed from Octopus. Seems very much like a permission error, but I don’t know what permissions I’d be missing.

TeamCity Build Log:

[12:24:01]Step 5/5: Create Release (OctopusDeploy: Create release) (1m:16s)
[12:24:02][Step 5/5] Octopus Deploy (1m:16s)
[12:24:02][Octopus Deploy] Running command:   octo.exe create-release --server http://**** --apikey SECRET --project **** --enableservicemessages --version 1.0.58.0 --deployto Development
...
[12:24:03][Octopus Deploy] Finding latest NuGet package for step: Deploy
[12:25:18][Octopus Deploy] Error from Octopus server (HTTP 500): Octopus Server returned an error: An error occurred while loading packages from 'http://****/httpAuth/app/nuget/v1/FeedService.svc/': The remote server returned an error: (401) Unauthorized.
[12:25:18][Octopus Deploy] Exit code: -7
[12:25:18][Octopus Deploy] Octo.exe exit code: -7

Octopus Server Log:

System.Net.WebException: The remote server returned an error: (401) Unauthorized.
   at System.Net.HttpWebRequest.GetResponse()
   at NuGet.RequestHelper.GetResponse()
   at NuGet.RedirectedHttpClient.GetResponseUri(HttpClient client)
   at NuGet.RedirectedHttpClient.EnsureClient()
   at System.Lazy`1.CreateValue()
   at Octopus.Server.Web.Api.Actions.PackageSearchAction.Execute() in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Api\Actions\PackageSearchAction.cs:line 56
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Respond(TDescriptor options, NancyContext context) in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 162
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Octopus.Server.Web.Api.OctopusRestApiModule.<>c__DisplayClass0_0.<.ctor>b__0(Object o) in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Api\OctopusRestApiModule.cs:line 46
   at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context)
--- End of stack trace from previous location where exception was thrown ---
   at System.Lazy`1.LazyInitValue()
   at NuGet.MemoryCache.GetOrAdd[T](Object cacheKey, Func`1 factory, TimeSpan expiration, Boolean absoluteExpiration)
   at NuGet.RedirectedHttpClient.get_CachedClient()
   at NuGet.RedirectedHttpClient.get_Uri()
   at NuGet.DataServicePackageRepository.get_Context()
   at NuGet.DataServicePackageRepository.GetPackages()
   at Octopus.Core.Packages.ExternalNuGetFeedAdapter.SearchForPackagesNamedLike(String packageId, Int32 take) in Y:\work\refs\tags\3.3.6\source\Octopus.Core\Packages\ExternalNuGetFeedAdapter.cs:line 86
   at Octopus.Core.Packages.ExternalNuGetFeedAdapter.GetPackagesContaining(String searchTerm, Int32& total, Int32 skip, Int32 take, Boolean allowPreRelease) in Y:\work\refs\tags\3.3.6\source\Octopus.Core\Packages\ExternalNuGetFeedAdapter.cs:line 66
   at Octopus.Server.Web.Api.Actions.PackageSearchAction.Search(String feedId, String packageId, Boolean partialMatch, Boolean includeMultipleVersions, Boolean includeNotes, Boolean includePreRelease, Int32 take, IVersionSpec versionRange, Regex preReleaseTag) in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Api\Actions\PackageSearchAction.cs:line 76
   at Octopus.Server.Web.Api.Actions.PackageSearchAction.Execute() in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Api\Actions\PackageSearchAction.cs:line 56
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Respond(TDescriptor options, NancyContext context) in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 162
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Octopus.Server.Web.Api.OctopusRestApiModule.<>c__DisplayClass0_0.<.ctor>b__0(Object o) in Y:\work\refs\tags\3.3.6\source\Octopus.Server\Web\Api\OctopusRestApiModule.cs:line 46
   at Nancy.Routing.Route.<>c__DisplayClass4.b__3(Object parameters, CancellationToken context)

Hi Kayla,

Thanks for getting in touch. It certainly does look like a permissions issue. Possibly expired or changed credentials in Octopus for the connection to TeamCity. A couple of things worth trying would be

  • test the feed through the Octopus UI to make see if you get the same behaviour
  • double check which credentials have been configured on the external feed
  • temporarily enable the public feed in TeamCity (if it isn’t already enabled) and switch to that to see if the deployment goes through

Hope that helps and let me know if I can be of further assistance.

Shannon

Hi Shannon,

Thanks for the response! I tested the feed through Octopus and got the same behavior. When enabling the public feed in TeamCity, I was able to successfully deploy.

I know this may be more of a TeamCity question, but how do I check the credentials on the external feed? I tested running octo.exe with my user, and I should have admin access on TeamCity and the Octopus server. What am I missing?

Thanks,
Kayla

Hi Kayla,

TeamCity uses HTTP BASIC authentication on its feed, i.e. username/password. So you should typically just need the username and password of a TeamCity user entered in the External Feed configuration in Octopus Server.

Another test that might be worth trying is to get the NuGet command line exe. If you check out the documentation on using sources and then use the list command to access the feed. This may give you more detailed information on what’s failing with the authentication.

The commands would be along the lines of

nuget sources Add -Name TeamCity -Source http://???/httpAuth/app/nuget/v1/FeedService.svc -username ??? -password ???
nuget list -Source TeamCity

Shannon

That was it! Another TeamCity admin edited the credentials for the account used to access the external feed. Updating the username and password in the external feed config on the Octopus Server worked.

Thanks for your help,
Kayla

Hi Kayla,

Glad to hear you got it working.

Shannon