Programmatically detect which deployment is occurring, when running under Octopus

We have an in-house application which is used as part of an Octopus deployment. The same application is also used by developers on their own machines. We want this application to be able to detect when it is running as part of an Octopus deployment, and be able to detect information about that deployment, so that we can record that a particular change was caused by a particular Octopus deployment.

We could do this by requiring people to pass command-line parameters to our application when they use it as part of an Octopus deployment (e.g. if they are calling it from PowerShell, they could use the Octopus variables which are exposed to PowerShell). However, if the developer forgets to pass those parameters, or passes incorrect values (e.g. by using the wrong variables) then this will record incorrect information.

Ideally, we want the running application being able to detect this information directly. I was trying to do this by using the “TentacleJournal” environment variable, and then looking up the entry in the journal where the “Deployment” node has “ExtractedTo” attribute equal to the “OctopusCalamariWorkingDirectory” environment variable (which gives me the Environment/Tenant/Project/Package/PackageVersion - perfect!). However, that journal entry is only written after the deployment has finished, so the application (which is running during the deployment) can’t use it because it won’t exist yet.

I would even be happy with something like a DeploymentId, so the application can fetch further details about it from the OctopusClientApi; although when I tried [C#] “new OctopusRepository(endpoint).Deployments.Get(deploymentId)”, with the Deployment/Id values from the journal, it throws OctopusResourceNotFoundException.

Clearly I can use “TentacleJournal” to detect that it is being run by Octopus; but can you advise how I might be able to detect which deployment the application is part of?


I’ve just spotted that the Deployment/Id in the journal is a Guid, and the values for “Id” for Deployments in the OctopusClient API are things like “Deployments-163397”, so that explains why it’s not found. The core part of the question still stands.

Greetings Richard! This situation is complex enough that I think it would be best to get on a call so you can show me rather than trying to go back and forth over messages. Would you be opposed to hopping on a call and walking me through your scenario?



Thanks, Shawn, that would be great. If you’d like to email me, we can set up a call.

Hey there Richard! It doesn’t look like I can find your email address. If you wouldn’t mind emailing, I’ll snag the ticket and send you a link to schedule something. Will that work?



Done :slight_smile:

Thanks to the guys at Octopus for the meeting this morning. Although there isn’t a way of doing what I was hoping, we’ve got a proposed solution which I think is going to work.

If I wrap up the way our application is called into a package-deploying Template Step, then the template could ensure that a new parameter is passed, with the value of the “Octopus.Deployment.Id” variable. Our application can use the existence of the Octopus/Tentacle environment variables to detect that it is being run by Octopus, and use that to enforce that the new parameter is being supplied. There’s no guarantee that someone isn’t calling our application themselves, and passing the wrong value; but that’s the problem with trying to make things foolproof - fools can be very creative.

I’ve been able to run some initial tests since this morning’s meeting, and the early signs are this looks like it’s going to work.
Thanks again, guys.

Glad Mark was able to assist :slight_smile: