Skip to content

Commit 0ca658b

Browse files
committed
[JENKINS-42846] - Rename the jenkins-slave script to jenkins-agent
1 parent 15ebbef commit 0ca658b

2 files changed

Lines changed: 102 additions & 1 deletion

File tree

jenkins-agent

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env sh
2+
3+
# The MIT License
4+
#
5+
# Copyright (c) 2015-2019, CloudBees, Inc.
6+
#
7+
# Permission is hereby granted, free of charge, to any person obtaining a copy
8+
# of this software and associated documentation files (the "Software"), to deal
9+
# in the Software without restriction, including without limitation the rights
10+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
# copies of the Software, and to permit persons to whom the Software is
12+
# furnished to do so, subject to the following conditions:
13+
#
14+
# The above copyright notice and this permission notice shall be included in
15+
# all copies or substantial portions of the Software.
16+
#
17+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
# THE SOFTWARE.
24+
25+
# Usage jenkins-agent.sh [options] -url http://jenkins [SECRET] [AGENT_NAME]
26+
# Optional environment variables :
27+
# * JENKINS_TUNNEL : HOST:PORT for a tunnel to route TCP traffic to jenkins host, when jenkins can't be directly accessed over network
28+
# * JENKINS_URL : alternate jenkins URL
29+
# * JENKINS_SECRET : agent secret, if not set as an argument
30+
# * JENKINS_AGENT_NAME : agent name, if not set as an argument
31+
# * JENKINS_AGENT_WORKDIR : agent work directory, if not set by optional parameter -workDir
32+
33+
if [ $# -eq 1 ]; then
34+
35+
# if `docker run` only has one arguments, we assume user is running alternate command like `bash` to inspect the image
36+
exec "$@"
37+
38+
else
39+
40+
# if -tunnel is not provided, try env vars
41+
case "$@" in
42+
*"-tunnel "*) ;;
43+
*)
44+
if [ ! -z "$JENKINS_TUNNEL" ]; then
45+
TUNNEL="-tunnel $JENKINS_TUNNEL"
46+
fi ;;
47+
esac
48+
49+
# if -workDir is not provided, try env vars
50+
if [ ! -z "$JENKINS_AGENT_WORKDIR" ]; then
51+
case "$@" in
52+
*"-workDir"*) echo "Warning: Work directory is defined twice in command-line arguments and the environment variable" ;;
53+
*)
54+
WORKDIR="-workDir $JENKINS_AGENT_WORKDIR" ;;
55+
esac
56+
fi
57+
58+
if [ -n "$JENKINS_URL" ]; then
59+
URL="-url $JENKINS_URL"
60+
fi
61+
62+
if [ -n "$JENKINS_NAME" ]; then
63+
JENKINS_AGENT_NAME="$JENKINS_NAME"
64+
fi
65+
66+
if [ -z "$JNLP_PROTOCOL_OPTS" ]; then
67+
echo "Warning: JnlpProtocol3 is disabled by default, use JNLP_PROTOCOL_OPTS to alter the behavior"
68+
JNLP_PROTOCOL_OPTS="-Dorg.jenkinsci.remoting.engine.JnlpProtocol3.disabled=true"
69+
fi
70+
71+
# if java home is defined, use it
72+
JAVA_BIN="java"
73+
if [ "$JAVA_HOME" ]; then
74+
JAVA_BIN="$JAVA_HOME/bin/java"
75+
fi
76+
77+
# if both required options are defined, do not pass the parameters
78+
OPT_JENKINS_SECRET=""
79+
if [ -n "$JENKINS_SECRET" ]; then
80+
case "$@" in
81+
*"${JENKINS_SECRET}"*) echo "Warning: SECRET is defined twice in command-line arguments and the environment variable" ;;
82+
*)
83+
OPT_JENKINS_SECRET="${JENKINS_SECRET}" ;;
84+
esac
85+
fi
86+
87+
OPT_JENKINS_AGENT_NAME=""
88+
if [ -n "$JENKINS_AGENT_NAME" ]; then
89+
case "$@" in
90+
*"${JENKINS_AGENT_NAME}"*) echo "Warning: AGENT_NAME is defined twice in command-line arguments and the environment variable" ;;
91+
*)
92+
OPT_JENKINS_AGENT_NAME="${JENKINS_AGENT_NAME}" ;;
93+
esac
94+
fi
95+
96+
#TODO: Handle the case when the command-line and Environment variable contain different values.
97+
#It is fine it blows up for now since it should lead to an error anyway.
98+
99+
ls -la /usr/share/jenkins/
100+
exec $JAVA_BIN $JAVA_OPTS $JNLP_PROTOCOL_OPTS -cp /usr/share/jenkins/agent.jar hudson.remoting.jnlp.Main -headless $TUNNEL $URL $WORKDIR $OPT_JENKINS_SECRET $OPT_JENKINS_AGENT_NAME "$@"
101+
fi

jenkins-agent.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Param(
3131
$JavaHome = $env:JAVA_HOME
3232
)
3333

34-
# Usage jenkins-slave.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
34+
# Usage jenkins-agent.ps1 [options] -Url http://jenkins -Secret [SECRET] -Name [AGENT_NAME]
3535
# Optional environment variables :
3636
# * JENKINS_TUNNEL : HOST:PORT for a tunnel to route TCP traffic to jenkins host, when jenkins can't be directly accessed over network
3737
# * JENKINS_URL : alternate jenkins URL

0 commit comments

Comments
 (0)