forked from royingantaginting/jenkins-slave-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slave.jnlp.sh
executable file
·76 lines (67 loc) · 2.25 KB
/
slave.jnlp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
JENKINS_HOME=$( dirname $0 )
JENKINS_CONF=${JENKINS_HOME}/Library/Preferences/org.jenkins-ci.slave.jnlp.conf
#JENKINS_WRKSPC=${HOME}/Library/Developer/org.jenkins-ci.slave.jnlp
JENKINS_WRKSPC=${JENKINS_HOME}
JENKINS_SLAVE=`hostname -s | tr '[:upper:]' '[:lower:]'`
JENKINS_MASTER=http://jenkins
HTTP_PORT=''
JENKINS_USER=''
JENKINS_TOKEN=''
JAVA_ARGS='-Djava.awt.headless=true'
JAVA_ARGS_LOG=''
# called when unloaded by launchctl
function unload() {
PID=`cat ${JENKINS_WRKSPC}/.slave.pid`
if [ "$PID" != "" ]; then
kill $PID
wait $PID
fi
echo
echo "Stopping at `date`"
echo
exit 0
}
# launchctl sends SIGTERM to unload a daemon
# trap SIGTERM to be able to gracefully cleanup
trap "unload" HUP INT TERM
if [ -f ${JENKINS_CONF} ]; then
chmod 400 ${JENKINS_CONF}
source ${JENKINS_CONF}
fi
[ ! -z $HTTP_PORT ] && HTTP_PORT=":${HTTP_PORT}"
JENKINS_SLAVE_ESC=$( echo -ne "${JENKINS_SLAVE}" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | cut -c 3- )
JENKINS_JNLP_URL=${JENKINS_MASTER}${HTTP_PORT}/computer/${JENKINS_SLAVE_ESC}/slave-agent.jnlp
echo
echo "Starting at `date`"
echo
# Create and switch to working directory
if ! cd ${JENKINS_WRKSPC} ; then
echo "Unable to use expected workspace: ${JENKINS_WRKSPC}"
exit 1
fi
# Download slave.jar. This ensures that everytime this daemon is loaded, we get the correct slave.jar
# from the Master. We loop endlessly to get the jar, so that if we start before networking, we ensure
# the jar gets loaded anyway.
echo "Getting slave.jar from ${JENKINS_MASTER}"
RESULT=-1
while [ true ]; do
curl --url ${JENKINS_MASTER}${HTTP_PORT}/jnlpJars/slave.jar --insecure --output ${JENKINS_WRKSPC}/slave.jar
RESULT=$?
if [ $RESULT -eq 0 ]; then
break
else
sleep 60
fi
done
echo "Launching slave process at ${JENKINS_JNLP_URL}"
RESULT=-1
# The user and API token are required for Jenkins >= 1.498
if [ ! -z ${JENKINS_USER} ]; then
JENKINS_USER="-jnlpCredentials ${JENKINS_USER}:"
fi
echo "Calling java ${JAVA_ARGS_LOG} -jar ${JENKINS_WRKSPC}/slave.jar -jnlpUrl ${JENKINS_JNLP_URL} ${JENKINS_USER}********"
java ${JAVA_ARGS} -jar ${JENKINS_WRKSPC}/slave.jar -jnlpUrl ${JENKINS_JNLP_URL} ${JENKINS_USER}${JENKINS_TOKEN} &
echo $! > ${JENKINS_WRKSPC}/.slave.pid
wait `cat ${JENKINS_WRKSPC}/.slave.pid`
unload