I've just encountered this problem, and it actually looks like an issue in /etc/init.d/jenkins
testing for the Java version. I just posted a solution here: https://dorian.fraser-moore.com/works/5054500/ubuntu-and-jenkins-found-an-incorrect-java-version , sharing below for those who find this question as first google hit.
Following a recent update to my Ubuntu 20.04.1 LTS dev server my installation of Jenkins stopped running on boot. Checking systemctl status jenkins.service
returned back this set of messages
Nov 13 09:35:43 tattve jenkins[1038744]: Found an incorrect Java version
Nov 13 09:35:43 tattve jenkins[1038744]: Java version found:
Nov 13 09:35:43 tattve jenkins[1038776]: openjdk version "11.0.9.1" 2020-11-04
Nov 13 09:35:43 tattve jenkins[1038776]: OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
Nov 13 09:35:43 tattve jenkins[1038776]: OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
Nov 13 09:35:43 tattve jenkins[1038744]: Aborting
Which seemed odd, as jenkins support Java 11 and openJDK, indeed I'd been running that before.
Digging around a bit I noticed the init script in /etc/init.d/jenkins
that the script, at lines 56-60, was using SED to extract the version from the java - version command into a numeric value, but the regular expression was a bit to broad
# Which Java versions can be used to run Jenkins
JAVA_ALLOWED_VERSIONS=( "18" "110" )
# Work out the JAVA version we are working with:
JAVA_VERSION=$($JAVA -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')
It turns out this last line was setting JAVA_VERSION to 11.09 which doesn't match anything in JAVA_ALLOWED_VERSION. I could add 11.09 to JAVA_ALLOWED_VERSIONS to make it run, but a better fix seem to be to fix that permissive sed line. Changing it to:
JAVA_VERSION=$($JAVA -version 2>&1 | sed -n ';s/.* version "\([0-9]*\)\.\([0-9]*\)\..*".*/\1\2/p;')
Did the job. It might help someone else.
[Due Diligence Edit]
It looks like someone has already made a PR for a fix: https://github.com/jenkinsci/packaging/pull/198
systemctl daemon-reload
andsudo service jenkins start
after changing the jenkins startup script – Alupotha Nov 26 '20 at 03:38