TeamCity PlugIn : Unauthorized (401)

I’m using the TeamCity plugin and created a ‘OctopusDeploy: Release’ build step which fails with an Unauthorized response from the Octopus server.

@@@
[Octopus Deploy] Running command: octo.exe create-release --server=“http://ts-d-app-550:49020” --apikey=SECRET --project=“Central Logging” --enableservicemessages --version=“1.0.72.105” --deployto=“Integration” --waitfordeployment --packagesFolder=DeploymentArtifacts

[14:50:18][Octopus Deploy] Handshaking with Octopus server: http://ts-d-app-550:49020/api
[14:50:20][Octopus Deploy] Octopus server responded with: The remote server returned an error: (401) Unauthorized.
[14:50:20][Octopus Deploy] Please ensure your API key is valid. If Basic authentication is being used by IIS, you will also need to pass your username and password.
@@@

The build step includes a user API key and the Octopus server is secured with windows authentication with the Team City build agent service running under a domain account.

Can anyone provide any pointers as to why this configuration does not work?

Thanks, Nick

Hi Nick,

Can you verify that:

  1. You are getting your API key from the same place as the screenshots on this page:
    https://github.com/OctopusDeploy/Octopus-Tools
  2. Can you try calling octo.exe manually from the TeamCity server, passing the same arguments?

Also, is there a proxy server between your TeamCity and Octopus server?

Paul

Paul,

Thanks for the response.

1.) I can confirm the API key is being sourced from my profile on the Octopus portal.

2.) Unfortunately, I don’t have access to the TeamCity server to try octo.exe directly. However, does the build step for OctopusDeploy run on the TeamCity server or on the machine the Build Agent is running on? The reason I ask is that our build agent runs remotely from the server and wondered if that was a supported configuration. I do have access to the build agent machine.

As far as I’m aware there are no proxy servers invlolved.

Nick

Hi Nick,

You are right, the TeamCity build step calls Octo.exe from the build
agentrather than the build server. Could you try running Octo.exe on
the agent
to reproduce?

Regards,

Paul Stovell
Octopus Deploy
W: octopusdeploy.com | T: @octopusdeploy http://twitter.com/octopusdeploy

Paul,

I couldn’t find the location of octo.exe on the build agent, so I’m assuming its passed to it during a build?

I downloaded it from the downloads section and ran the command directly, replacing the ‘secret’ API key with the actual value, but it gave exactly the same 401 error.

FYI, If I try and browse to the api via a browser on the build agent I receive the same authentication challenge and am prompted to enter credentials.

Nick

Hi Nick,

Can you try passing those credentials via the --user and --pass parameters
when calling Octo.exe?

Regards,

Paul Stovell
Octopus Deploy
W: octopusdeploy.com | T: @octopusdeploy http://twitter.com/octopusdeploy

Paul,

That works, so I’ll use it as a stop gap.

The drawback is that we will have to store a user name and password in our TeamCity build configurations. I was hoping to take advantage of Windows Authentication.

Thanks for your help and swift responses.
Nick

Hi Nickj

i have the same issue but i am active directory authentication. it works great outside octo.exe but not within the context of the command line. If i hit the api, i can authenticate properly with ad accounts

Octopus Command Line Tool, version 1.1.17.62

Finding project: Project
Handshaking with Octopus server: http://xxx9006/api
Handshake successful. Octopus version: 1.6.0.1714; API version: 2.0.0
Finding environments…
Finding steps for project…
Resolving NuGet package versions…

  • Finding latest NuGet package for step: Deploy To Dev
    Octopus server responded with: The remote server returned an error: (400) Bad Request.
    System.Net.WebException: The remote server returned an error: (400) Bad Request.
    at System.Net.HttpWebRequest.GetResponse()
    at OctopusTools.Client.OctopusSession.Get[TResource](String path, QueryString queryString)
    at OctopusTools.Client.OctopusSession.Get[TResource](String path)
    at OctopusTools.Client.OctopusSession.List[TResource](String path)
    at ProjectExtensions.GetLatestPackageForStep(IOctopusSession session, Step step)
    at OctopusTools.Commands.CreateReleaseCommand.Execute()
    at OctopusTools.Infrastructure.CommandProcessor.Process(String[] args)

Hi Augusto,

From that log you seem to be authenticating fine (“Handshake successful. Octopus version: 1.6.0.1714; API version: 2.0.0”). The problem comes when listing NuGet package versions. Could you check the Windows event viewer on the Octopus server to see if any other details are included?

Paul

Paul: here is the log entry that it is created.

2013-05-08 23:44:24,963 [8] ERROR Octopus [(null)] - System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at NuGet.RequestHelper.GetResponse(Func1 createRequest, Action1 prepareRequest, IProxyCache proxyCache, ICredentialCache credentialCache, ICredentialProvider credentialProvider)
at NuGet.HttpClient.GetResponse()
at NuGet.RedirectedHttpClient.GetResponseUri(HttpClient client)
at NuGet.RedirectedHttpClient.EnsureClient()
at System.Lazy1.CreateValue() at System.Lazy1.LazyInitValue()
at NuGet.RedirectedHttpClient.get_CachedClient()
at NuGet.RedirectedHttpClient.get_Uri()
at NuGet.DataServicePackageRepository.get_Context()
at NuGet.DataServicePackageRepository.FindPackagesById(String packageId)
at Octopus.Portal.Areas.Api.Controllers.PackagesController.FindPackageNamed(IPackageRepository repository, String packageId, Int32 take)
at Octopus.Portal.Areas.Api.Controllers.PackagesController.Index(String feedId, String packageId, Boolean partialMatch, Boolean includeMultipleVersions, Int32 take)
at lambda_method(Closure , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.b__41()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.b__33()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.b__49()

It looks like a problem with communicating to the NuGet server.

Can you go to the Configuration -> NuGet page and use the Test links to
check that the NuGet server is responding? Perhaps the credentials are
invalid.

Regards,

Paul Stovell
Octopus Deploy
W: octopusdeploy.com | T: @octopusdeploy http://twitter.com/octopusdeploy

Paul, I am getting the same error. I am using --user and --pass, and the Test link works 100%.

Stack Trace is:

[Octopus Deploy] Finding project: Online
[10:04:10][Octopus Deploy] Handshaking with Octopus server: http://slbapptst064v:9001/api
[10:04:10][Octopus Deploy] Octopus server responded with: The remote server returned an error: (401) Unauthorized.
[10:04:10][Octopus Deploy] Please ensure your API key is valid. If Basic authentication is being used by IIS, you will also need to pass your username and password.
[10:04:10][Octopus Deploy] System.Net.WebException: The remote server returned an error: (401) Unauthorized.
[10:04:10][Octopus Deploy] at System.Net.HttpWebRequest.GetResponse()
[10:04:10][Octopus Deploy] at OctopusTools.Client.OctopusSession.Get[TResource](String path, QueryString queryString)
[10:04:10][Octopus Deploy] at OctopusTools.Client.OctopusSession.EstablishSession()
[10:04:10][Octopus Deploy] at System.Lazy1.CreateValue() [10:04:10][Octopus Deploy] at System.Lazy1.LazyInitValue()
[10:04:10][Octopus Deploy] at System.Lazy`1.get_Value()
[10:04:10][Octopus Deploy] at OctopusTools.Client.OctopusSession.get_RootDocument()
[10:04:10][Octopus Deploy] at ProjectExtensions.GetProject(IOctopusSession session, String projectName)
[10:04:10][Octopus Deploy] at OctopusTools.Commands.CreateReleaseCommand.Execute()
[10:04:10][Octopus Deploy] at OctopusTools.Infrastructure.CommandProcessor.Process(String[] args)
[10:04:10][Octopus Deploy] Octo.exe exit code: 2

Hi,

This is now a different problem - your API key looks like it is not valid. Where did you copy the API key value from?

Paul

Sorry, it was my fault. I was using the wrong API key. I found a comment in
another page which showed me what I was doing wrong.

I’m currently out of the office until Monday 14th October 2013 and will deal with your email on my return

If your enquiry is urgent please contact James Scanlan (james.scanlan@hscic.gov.uk)


This message may contain confidential information. If you are not the intended recipient please inform the
sender that you have received the message in error before deleting it.
Please do not disclose, copy or distribute information in this e-mail or take any action in reliance on its contents:
to do so is strictly prohibited and may be unlawful.

Thank you for your co-operation.

NHSmail is the secure email and directory service available for all NHS staff in England and Scotland
NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and GSi recipients
NHSmail provides an email address for your career in the NHS and can be accessed anywhere