Bamboo Spec scanning fails with JAVA_HOME variable is not set correctly
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
Bamboo Spec scanning from linked Bitbucket repositories fails with error > JAVA_HOME variable is not set correctly.
Environment
Any supported Bamboo Environment , Issue is seen in 8.0.4.
Diagnosis
For the diagnosis , Please refer atlassian-bamboo.log and look for the below error.
The snippet in the log is from pom.xml file for the specs scanner which resides in <Bamboo-Install>/atlassian-bamboo/WEB-INF/classes/bamboo-specs-pom.xml.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/dependencies>
06-Jan-2022 12:44:32 <build>
06-Jan-2022 12:44:32 <plugins>
06-Jan-2022 12:44:32 <plugin>
06-Jan-2022 12:44:32 <groupId>org.apache.maven.plugins</groupId>
06-Jan-2022 12:44:32 <artifactId>maven-compiler-plugin</artifactId>
06-Jan-2022 12:44:32 <configuration>
06-Jan-2022 12:44:32 <compilerArgs>
06-Jan-2022 12:44:32 <compilerArg>-proc:none</compilerArg>
06-Jan-2022 12:44:32 </compilerArgs>
06-Jan-2022 12:44:32 </configuration>
06-Jan-2022 12:44:32 </plugin>
06-Jan-2022 12:44:32 </plugins>
06-Jan-2022 12:44:32 </build>
06-Jan-2022 12:44:32 </project>
06-Jan-2022 12:44:32 The JAVA_HOME environment variable is not defined correctly
06-Jan-2022 12:44:32 This environment variable is needed to run this program
06-Jan-2022 12:44:32 NB: JAVA_HOME should point to a JDK not a JRE
Cause
There are possible 2 causes of the Issue.
Incorrect JAVA_HOME setup.
Maven not correctly configured on the system.
Please refer below steps on how to validate the above 2 points.
Cause 1
JAVA_HOME variable not set correctly (Instead of JDK, it is pointing to JRE).
Please validate JAVE_HOME in bamboo server is configured correctly with bamboo user using this command:
1
echo $JAVA_HOME
The output should point to a jdk folder and not jre. Sample output:
1
/usr/lib/jvm/java-1.8.0-openjdk/jre
If the output is wrong and pointing to jre instead of jdk ( /opt/java/openjdk/jre) then the problem is with JAVA_HOME variable.
Cause 2
Maven not correctly configured in the Bamboo servers.
mvn version is pointing to wrong JAVA_HOME location , this can be validated by running the command:
1
mvn -version
Here we can see maven is referring to wrong Java path which is /usr/lib/jvm/java-1.8.0-openjdk/jre:
1
2
3
4
5
6
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_45, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/java-1.8.0-openjdk/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-30-generic", arch: "amd64", family: "unix"
Solution
Solution will depends upon the cause identified from above , please refer both the solutions below based on the cause identified in the section above.
Solution 1
Incorrect JAVA_HOME
To correct JAVA_HOME path , please refer setting JAVA_HOME
Solution 2
Maven not reading correct JAVA_HOME
The best way to force a specific JVM for MAVEN is to create a system wide file loaded by the mvn script. This file is /etc/mavenrc
and it must declare a JAVA_HOME
environment variable pointing to your specific JVM.
Example:
1
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
If the file exists, it's loaded. Please make sure the current Bamboo user has access to this file and is referencing it.
Here is an extract of the mvn
script in order to understand.
1
2
3
4
5
6
7
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
Alternately, the same content can be written in ~/.mavenrc.
Restart Bamboo after making changes to this file.
Was this helpful?