C# api fails under teamcity

(Nate Barish) #1

I have a c# app that uses the Octopus.Client library v5.2.0. The app works as expected when run from the command line. However when this app is run as part of a teamcity build the app fails with the error below.

The resource you requested was not found.

at Octopus.Client.OctopusClient.DispatchRequest[TResponseResource](OctopusRequest request, Boolean readResponse)
at Octopus.Client.OctopusClient.Get[TResource](String path, Object pathParameters)
at Octopus.Client.OctopusClient.EstablishSession()
at Octopus.Client.OctopusClient.get_RootDocument()
at Octopus.Client.Repositories.CertificateConfigurationRepository.DetermineCollectionLinkName(IOctopusClient client)   
at Octopus.Client.OctopusRepository..ctor(IOctopusClient client)

This happens when the app first tries to connect to the octopus server.

_octopus = new OctopusRepository(new OctopusServerEndpoint(octoUrl, octoKey));

I can see in the application logs that when the application is started as part of a teamcity build the logger Octopus.Client.AutomationEnvironments.AutomationEnvironmentProvider logs this:

Detected automation environment: TeamCity/2017.1.1

where as when run from the command line it logs

Detected automation environment: NoneOrUnknown

(Matthew Casperson) #2

Hi Nate, thanks for reaching out.

The OctopusResourceNotFoundException is generated because a network request resulted in a HTTP 404 not found response. This may be generated because the Octopus URL is not set correctly, or maybe a network device like a firewall or proxy is returning a 404.

The only thing I can suggest here is to try and isolate any differences between the code being run in Team City and locally i.e. ensure the API key, the Octopus URL and any proxy or firewall settings are replicated when running locally.

You may also try running the Octopus CLI fro Team city (https://octopus.com/docs/api-and-integration/octo.exe-command-line), as this too is a C# executable that uses the Octopus client library. If the Octopus CLI also returns errors when trying to access the Octopus server, it would indicate a problem outside of your code.

The different log outputs of Detected automation environment: TeamCity/2017.1.1 and Detected automation environment: NoneOrUnknown are the result of the client library detecting an environment variable when the code is run from Team City or locally. This output is expected, but won’t change the network requests made to Octopus.

Matt C

(Nate Barish) #3

I seems unlikely that its a firewall issue. I was able to run the same exe from the command line on the build agent and it was able to reach the octopus server without issue.

I wasn’t very clear in the original post but this issue is new in v5.2.0 if I downgrade back down to v4.22.1 the issue goes away.

(Matthew Casperson) #4

Hi Nate, which version of the Octopus server are you connecting to?

Version 5 of the client library has changes to support the new spaces feature in Octopus 2019.1, which could explain why version 4 of the client library works as expected.

Matt C

(Nate Barish) #5

Server version is 3.16.2

(Matthew Casperson) #6

Hi Nate,

For versions prior to 2019.1 your scripts should be using client version 4. You’ll only need version 5 if you upgrade the server.

Matt C

(system) closed #7

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.