Skip to content

Commit

Permalink
Merge pull request jenkinsci#54 from oleg-nenashev/workdir-env-var
Browse files Browse the repository at this point in the history
 Add JENKINS_AGENT_WORKDIR env var (update of jenkinsci#44)
  • Loading branch information
oleg-nenashev authored and lemeurherve committed Dec 26, 2017
1 parent 2200e99 commit 35d6f7e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion jenkins-slave
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# * JENKINS_URL : alternate jenkins URL
# * JENKINS_SECRET : agent secret, if not set as an argument
# * JENKINS_AGENT_NAME : agent name, if not set as an argument
# * JENKINS_AGENT_WORKDIR : agent work directory, if not set by optional parameter -workDir

if [ $# -eq 1 ]; then

Expand All @@ -45,6 +46,15 @@ else
fi ;;
esac

# 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" ;;
*)
WORKDIR="-workDir $JENKINS_AGENT_WORKDIR" ;;
esac
fi

if [ -n "$JENKINS_URL" ]; then
URL="-url $JENKINS_URL"
fi
Expand Down Expand Up @@ -80,5 +90,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 $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@"
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 "$@"
fi

0 comments on commit 35d6f7e

Please sign in to comment.