Accessing existing machine environment variables in PreDeploy script

I’m trying to access an existing machine environment variable from within my PreDeploy script, however it seems to never be there…

Specifically, I’m looking for the CATALINA_HOME environment variable used by Tomcat:

$EnvVariable = "CATALINA_HOME"
if (Test-Path Env:$EnvVariable) {
Write-Host -foregroundcolor green “Required environment variable $EnvVariable is set.”
else {
throw "Environment variable $EnvVariable is not set. This must be set to the Tomcat folder location."
exit 1

This environment variable is definitely on the machine - I can verify that by logging on and seeing it - it is also at Machine level.

Is there something in the way PreDeploy is executed in Powershell that prevents it from seeing this variable? Is it that all deployment scripts are run in a continuous single session and that I would need to restart Octopus for the script to see it?

Hi David,

You will need to restart the Tentacle agent on the remote machine after setting the environment variable for it to be picked up. I’ll see if there’s a way I can refresh the environment variables automatically going forward.


Sent from my Windows Phone

From: David Duffett
Sent: 16/08/2012 12:49
To: Paul Stovell
Subject: Accessing existing machine environment variables in PreDeploy script [Questions #218]

Thanks Paul - thought that might be the case.