Incorrect environment variables when running remote agent on macOS
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
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
After installing the remote agent as a daemon on macOS builds start to fail because environment variables are not being picked.
Diagnosis
Create a test plan with a script task to print the environment variables:
echo $JAVA_HOME
echo $PATH
Cause
By default, the macOS daemon does not pick environment variables.
Solution
There are two possible solutions for this issue. We can either set the environment variables on the plist file or at wrapper.conf:
Option A
You can set the environment variables in <Bamboo agent home>/conf/wrapper.conf, copy your JAVA_HOME and PATH and insert them in the wrapper configuration. E.g.
# Allow the service to interact with the desktop.
wrapper.ntservice.interactive=FALSE
set.JAVA_HOME=/path/here
set.PATH=/path
Restart the service.
More information on Wrapper environment variables configuration: Environment Variable Definition
Option B
You can configure them in the plist file {{/Library/LaunchDaemons/org.tanukisoftware.wrapper.bamboo-agent.plist}} like in the example below. Add the following inside the dict:
<key>EnvironmentVariables</key>
<dict>
<key>JAVA_HOME</key>
<string>/Library/Java/JavaVirtualMachines/jdk1.8.0_212.jdk/Contents/Home</string>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin</string>
</dict>
Then reload the daemon:
sudo launchctl unload -w /Library/LaunchDaemons/org.tanukisoftware.wrapper.bamboo-agent.plist
sudo launchctl load -w /Library/LaunchDaemons/org.tanukisoftware.wrapper.bamboo-agent.plist
Option C
You can configure them using launchctl setenv command by executing the below sample commands:
sudo launchctl setenv JAVA_HOME $JAVA_HOME
sudo launchctl setenv PATH $PATH
Once the requirement environment variables are set, restart the Bamboo service.