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?
Thanks