Fix script task failures due to incorrect JAVA_HOME in Bamboo Data Center
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
After upgrading Bamboo from version 9.3.6 to 9.6.5, build failures were encountered due to an incorrect JAVA_HOME configuration. The problem was identified in the configuration of the Bamboo remote agent service, where the JAVA_HOME path was incorrectly set.
Environment
Bamboo Version: 9.3.6 and 9.6.5
Operating System: Linux (using systemd for service management)
Java Versions: Temurin JDK 17 and JDK 11
Diagnosis
The Bamboo user doesn't have a JAVA_HOME defined in their environment variables
Script tasks default to using JAVA_HOME for Temurin JDK 17.
This discrepancy was causing builds that rely on script tasks to fail, while those using Maven tasks, where the Java version can be specified directly, were unaffected.
Cause
This is due to the systemd unit file used to start the Bamboo remote agent. The JAVA_HOME environment variable was incorrectly set to include /bin/java, which should not be part of the JAVA_HOME path. This misconfiguration led to the following error during builds:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
Solution
Use the following steps:
Locate the Unit File: Use the command
systemctl status remote-agent1
to find the path to the unit file for the Bamboo remote agent.Edit the Unit File: Open the unit file and correct the JAVA_HOME path by removing
/bin/java
from the end of the path. The corrected configuration should look like this:[Unit] Description=Atlassian Bamboo After=syslog.target network.target [Service] Type=forking User=bamboo Environment="JAVA_HOME=/usr/lib/jvm/temurin-17-jdk" ExecStart=/opt/bamboo-remote1/bin/bamboo-agent.sh start ExecStop=/opt/bamboo-remote1/bin/bamboo-agent.sh stop SuccessExitStatus=143 [Install] WantedBy=multi-user.target
Restart the Bamboo Agent: After making the changes, restart the Bamboo agent using
systemctl restart remote-agent1.
Verify the Configuration: Ensure that the JAVA_HOME environment variable is now correctly set by running a script task that checks the JAVA_HOME value.
This will resolve the JAVA_HOME configuration issue, allowing builds to proceed without errors.
Was this helpful?