Virendar
Virendar

Reputation: 11

Unable to access environment variable in Bamboo Build Plan

I have a Bamboo Build Plan, with the following set of tasks.

  1. Source Code Checkout
  2. Artifactory Generic Resolve (To Get the zip file from Artifactory)
  3. Script (To Extract the contents of zip file and to set to CATALINA_HOME & PATH environment variable)
  4. Ant (For Build)

Task 3 has the following content in it:

APP_HOME=${bamboo.build.working.directory}
unzip $APP_HOME/tomcat/apache-tomcat-6.0.45-windows-x64.zip
export CATALINA_HOME=$APP_HOME/tomcat/apache-tomcat-6.0.45
export PATH="$PATH:$CATALINA_HOME/bin"

But when I execute 4th Task (Ant), the Build is not considering the CATALINA_HOME & PATH variable which is set as part of Task 3. What is wrong here? Why am I not able to access the environment variable that is set in Task 3?

Upvotes: 0

Views: 2383

Answers (1)

Boris Van Hardeveld
Boris Van Hardeveld

Reputation: 66

Every Script Task runs in its own non-interactive shell, eventually invoked through the ExternalProcessBuilder. Existing environment variables are made available to the process (i.e. shell), as well as the additional environment variables defined in the task itself as documented. However, newly exported variables are not carried over to the next task as it is an entirely new, isolated shell.

What you could do is to dump the export statements to a file, and 'source' that file at the start of the next script task.

Upvotes: 2

Related Questions