How to make environment variables available for Bamboo when running it as a Linux service

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

To simplify scripting in Bamboo we might need to have access to system variables.

Sevices try to preserve the application environment by stripping out variables other than TERM, PATH and LANG.

Solution

You will need to load the variables when calling Bamboo startup. Assuming the service was configured using Running Bamboo as a Linux service, these are the steps to solve this problem.

Using SysV script (/etc/init.d)

  1. Stop the service

  2. Create an external file with the variables you need (e.g. /etc/default/bamboo), please add the export command in front of them so they can be inherited.

    Sample content:

    1 2 export GEM_HOME=/home/bamboo/.rvm/gems/ruby-2.3.0 export GEM_PATH=/home/bamboo/.rvm/gems/ruby-2.3.0:/home/bamboo/.rvm/gems/ruby-2.3.0@global
  3. Edit the script /etc/init.d/bamboo to load the variable at Bamboo startup. Change the following line:

    From

    1 /bin/su - $USER -c "export BAMBOO_HOME=${BAMBOO_HOME}; $BASE/bin/startup.sh &> /dev/null"

    To

    1 /bin/su - $USER -c ". /etc/default/bamboo; export BAMBOO_HOME=${BAMBOO_HOME}; $BASE/bin/startup.sh &> /dev/null"
  4. Start the service again

Using systemd

  1. Stop the service

  2. Add the variable as an Environment or EnvironmentFile property to the service unit file. An example can be found on the Running Bamboo as a Linux service page

  3. Reload the service via systemctl daemon-reload

  4. Start the service

Updated on April 2, 2025

Still need help?

The Atlassian Community is here for you.