diff --git a/.buildkite/hooks/prepare-common.sh b/.buildkite/hooks/prepare-common.sh index 50b3d3388e..f5fc876099 100644 --- a/.buildkite/hooks/prepare-common.sh +++ b/.buildkite/hooks/prepare-common.sh @@ -5,19 +5,23 @@ set -euo pipefail JAVA_VERSION=$(cat .java-version | xargs | tr -dc '[:print:]') JAVA_HOME="${HOME}/.java/openjdk${JAVA_VERSION}" export JAVA_HOME -PATH="${JAVA_HOME}/bin:$PATH" +PATH="${JAVA_HOME}/bin:${PATH}" export PATH -# Fallback to install at runtime -if [ ! -d "${JAVA_HOME}" ] ; then +if [ -d "${JAVA_HOME}" ] ; then + echo "--- Skip installing JDK${JAVA_VERSION} :java:" + echo "already available in the Buildkite runner" +else + # Fallback to install at runtime # This should not be the case normally untless the .java-version file has been changed # and the VM Image is not yet available with the latest version. echo "--- Install JDK${JAVA_VERSION} :java:" JAVA_URL=https://jvm-catalog.elastic.co/jdk JAVA_PKG="${JAVA_URL}/latest_openjdk_${JAVA_VERSION}_linux.tar.gz" - curl -L --output /tmp/jdk.tar.gz "$JAVA_PKG" - mkdir -p "$JAVA_HOME" - tar --extract --file /tmp/jdk.tar.gz --directory "$JAVA_HOME" --strip-components 1 + curl -L --output /tmp/jdk.tar.gz "${JAVA_PKG}" + mkdir -p "${JAVA_HOME}" + tar --extract --file /tmp/jdk.tar.gz --directory "${JAVA_HOME}" --strip-components 1 fi +# Validate java is available in the runner. java -version