From: Anil Belur Date: Thu, 10 Jan 2019 01:03:11 +0000 (+1000) Subject: Fix version number extraction for all cases X-Git-Tag: v0.29.0~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F14%2F14114%2F1;p=releng%2Fglobal-jjb.git Fix version number extraction for all cases When the jobs upgrade to a later version of Java passing "openjdk11" or "openjdk10" the string substitution would only return the last char which would potentially fail to pick up the correct version of Java. This change fixes this issue to handle all cases. Change-Id: If81100bbdd116ee071c3ecdeeadc0a3016fa2a15 Signed-off-by: Anil Belur --- diff --git a/shell/update-java-alternatives.sh b/shell/update-java-alternatives.sh index 22147908..a53cc0ad 100644 --- a/shell/update-java-alternatives.sh +++ b/shell/update-java-alternatives.sh @@ -15,12 +15,12 @@ JAVA_ENV_FILE="/tmp/java.env" update-java-redhat() { - if [[ "${SET_JDK_VERSION: -2}" = "11" ]]; then + if [[ "${SET_JDK_VERSION//[a-zA-Z]/}" = "11" ]]; then export JAVA_HOME="/opt/jdk-11" - elif [[ "${SET_JDK_VERSION: -2}" = "10" ]]; then + elif [[ "${SET_JDK_VERSION//[a-zA-Z]/}" = "10" ]]; then export JAVA_HOME="/opt/jdk-10.0.2" else - export JAVA_HOME="/usr/lib/jvm/java-1.${SET_JDK_VERSION: -1}.0-openjdk" + export JAVA_HOME="/usr/lib/jvm/java-1.${SET_JDK_VERSION//[a-zA-Z]/}.0-openjdk" fi sudo /usr/sbin/alternatives --install /usr/bin/java java "${JAVA_HOME}/bin/java" 1 sudo /usr/sbin/alternatives --install /usr/bin/javac javac "${JAVA_HOME}/bin/javac" 1