From 62074482d19ea949b1247ddcf4232300a21a17ad Mon Sep 17 00:00:00 2001 From: bronogard <33424118+bronogard@users.noreply.github.com> Date: Tue, 10 Jul 2018 14:34:27 +0200 Subject: [PATCH] if java home is defined, use it --- jenkins-slave | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/jenkins-slave b/jenkins-slave index b4404c1e..4d893071 100755 --- a/jenkins-slave +++ b/jenkins-slave @@ -37,7 +37,7 @@ if [ $# -eq 1 ]; then else - # if -tunnel is not provided try env vars + # if -tunnel is not provided, try env vars case "$@" in *"-tunnel "*) ;; *) @@ -46,7 +46,7 @@ else fi ;; esac - # if -workDir is not provided try env vars + # if -workDir is not provided, try env vars if [ ! -z "$JENKINS_AGENT_WORKDIR" ]; then case "$@" in *"-workDir"*) echo "Warning: Work directory is defined twice in command-line arguments and the environment variable" ;; @@ -67,8 +67,14 @@ else echo "Warning: JnlpProtocol3 is disabled by default, use JNLP_PROTOCOL_OPTS to alter the behavior" JNLP_PROTOCOL_OPTS="-Dorg.jenkinsci.remoting.engine.JnlpProtocol3.disabled=true" fi + + # if java home is defined, use it + JAVA_BIN="java" + if [ "$JAVA_HOME" ]; then + JAVA_BIN="$JAVA_HOME/bin/java" + fi - # If both required options are defined, do not pass the parameters + # if both required options are defined, do not pass the parameters OPT_JENKINS_SECRET="" if [ -n "$JENKINS_SECRET" ]; then case "$@" in @@ -90,5 +96,5 @@ else #TODO: Handle the case when the command-line and Environment variable contain different values. #It is fine it blows up for now since it should lead to an error anyway. - exec java $JAVA_OPTS $JNLP_PROTOCOL_OPTS -cp /usr/share/jenkins/slave.jar hudson.remoting.jnlp.Main -headless $TUNNEL $URL $WORKDIR $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@" + exec $JAVA_BIN $JAVA_OPTS $JNLP_PROTOCOL_OPTS -cp /usr/share/jenkins/slave.jar hudson.remoting.jnlp.Main -headless $TUNNEL $URL $WORKDIR $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@" fi