This issue happens in cases where the jdk used by maven and the one used by Jenkins are not the same, eg: we would like to use an Agent Template
maven-jdk-7 i.e. using a Agent with Maven using Java 7
- CloudBees Jenkins Enterprise (CJE)
- Docker Template Agents with Maven and a JDK different that the one used by Jenkins
CloudBees only support JDK version 8 (CloudBees Supported Java) for any type of node.
It is extensible to Palace templates or Kubernetes Pod templates too.
Workaround: Create your own Docker Image (
Dockerfile) making available the JDK you need for Maven and a JDK 8 for
- In your
PATHyou declare the path to the Java 8 bin folder.
- In you docker image (or in the agent template configuration) you configure
JAVA_HOMEto point to the JDK of your interest and then Maven will use it.
- The normal procedure for providing tools to Agents (e.g JDK7) is via GUI Manage Jenkins > Global Tool Configuration but tools would be downloaded each time the agent is connected because it is Docker Agent (ephemeral), thus it is not recommended.
- The solution described only applies to Freestyle and Pipeline jobs. Maven jobs have the limitation described in (Maven jobs and Java versions compatibility). If you need to use Maven job, you will have to implement one of the solutions in (Maven jobs and Java versions compatibility).