Skip to content

Commit a4e516f

Browse files
authored
Merge pull request #860 from zhan9san/feature/jenkins-agent-jar-file
Add support for Jenkins agent jar file location in the environment variable JENKINS_AGENT_FILE
2 parents 93914be + a2eb9b2 commit a4e516f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README_inbound-agent.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Optional environment variables:
6161

6262
* `JENKINS_JAVA_BIN`: Path to Java executable to use instead of the default in PATH or obtained from JAVA_HOME
6363
* `JENKINS_JAVA_OPTS` : Java Options to use for the remoting process, otherwise obtained from JAVA_OPTS, **Warning** :exclamation: For more information on Windows usage, please see the **Windows Jenkins Java Opts** [section below](#windows-jenkins-java-opts).
64+
* `JENKINS_AGENT_FILE` : Jenkins agent jar file location, `/usr/share/jenkins/agent.jar` will be used if this is not set
6465
* `JENKINS_URL`: url for the Jenkins server, can be used as a replacement to `-url` option, or to set alternate jenkins URL
6566
* `JENKINS_TUNNEL`: (`HOST:PORT`) connect to this agent host and port instead of Jenkins server, assuming this one do route TCP traffic to Jenkins controller. Useful when when Jenkins runs behind a load balancer, reverse proxy, etc.
6667
* `JENKINS_SECRET`: (use only if not set as an argument) the secret as shown on the controller after creating the agent

jenkins-agent

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# Optional environment variables :
2727
# * JENKINS_JAVA_BIN : Java executable to use instead of the default in PATH or obtained from JAVA_HOME
2828
# * JENKINS_JAVA_OPTS : Java Options to use for the remoting process, otherwise obtained from JAVA_OPTS
29+
# * JENKINS_AGENT_FILE : Jenkins agent jar file location, /usr/share/jenkins/agent.jar will be used if this is not set
2930
# * REMOTING_OPTS : Generic way to pass additional CLI options to agent.jar (see -help)
3031
#
3132
# Deprecated environment variables (prefer setting REMOTING_OPTS)
@@ -109,6 +110,12 @@ else
109110
fi
110111
fi
111112

113+
if [ "$JENKINS_AGENT_FILE" ]; then
114+
AGENT_FILE="$JENKINS_AGENT_FILE"
115+
else
116+
AGENT_FILE="/usr/share/jenkins/agent.jar"
117+
fi
118+
112119
# if both required options are defined, do not pass the parameters
113120
if [ -n "$JENKINS_SECRET" ]; then
114121
case "$@" in
@@ -129,6 +136,6 @@ else
129136
#TODO: Handle the case when the command-line and Environment variable contain different values.
130137
#It is fine it blows up for now since it should lead to an error anyway.
131138

132-
exec $JAVA_BIN $JAVA_OPTIONS -jar /usr/share/jenkins/agent.jar $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $REMOTING_OPTS "$@"
139+
exec $JAVA_BIN $JAVA_OPTIONS -jar $AGENT_FILE $SECRET $AGENT_NAME $TUNNEL $URL $WORKDIR $WEB_SOCKET $DIRECT $PROTOCOLS $INSTANCE_IDENTITY $REMOTING_OPTS "$@"
133140

134141
fi

0 commit comments

Comments
 (0)