Before use this script please make sure things below you have done:
1.Install JDK on server
2.Create local user on server: jenkins
-3.Create the local workspace configured in jenkins
-3.Download slave.jar and put it into $HOME directory of jenkins user
-4.Your slave has been configured in OPNFV Jenkins
-5.Obtain slave's token from Linux Foundation Helpdesk
+3.Your slave has been configured in OPNFV Jenkins master
+4.Create slave's local workspace that has been configured in jenkins master
+5.Download slave.jar and put it into the folder of /home/jenkins/
+6.Obtain slave's token from Linux Foundation Helpdesk
Consult wiki : https://wiki.opnfv.org/wiki/jenkins#how_to_connect_servers_from_labs_to_opnfv_jenkins
Follow steps below to launch your slave to OPNFV Jenkins:
1. cp jenkins-slave.init /etc/init.d/jenkins-slave
2. chmod +x /etc/init.d/jenkins-slave
-3. define $SLAVENAME&$TOKEN in config file(jenkins-slave)
+3. Define $SLAVENAME&$TOKEN in config file(jenkins-slave)
4. cp jenkins-slave /etc/default/jenkins-slave
5. service jenkins-slave start
-Finally, run "service jenkins-slave status" command to check the process is running, see the log(/home/jenkins/slave.log) to confirm the connect to OPNFV Jenkins.
\ No newline at end of file
+
+Finally, run "service jenkins-slave status" command to check the process is running, see the log(/home/jenkins/jenkins-slave/slave.log) to confirm the connection to OPNFV Jenkins.
set -o pipefail
SLAVE_CONF="/etc/default/jenkins-slave"
-if [ -f ${SLAVE_CONF} ]; then
+
+if [ -f ${SLAVE_CONF} ]
+then
. ${SLAVE_CONF}
else
- echo "Fatal : Configuration file dosenot exist, details please refer to README."
+ echo "Error : Configuration file ($SLAVE_CONF) does not exist, details please refer to README."
exit
fi
if [ -z "${SLAVENAME}" ] || [ -z "${TOKEN}" ]
then
- echo "Fatal : Lack of slavename and token"
+ echo "Error : Please define SLAVENAME and TOKEN values in the Configuration file ($SLAVE_CONF), details please refer to README."
exit
fi
+SLAVE_JNLP="-jnlpUrl https://build.opnfv.org/ci/computer/${SLAVENAME}/slave-agent.jnlp"
JENKINS_HOME="/home/jenkins"
-PID_FILE="${JENKINS_HOME}/slave.pid"
SLAVE_JAR="${JENKINS_HOME}/slave.jar"
-SLAVE_JNLP="-jnlpUrl https://build.opnfv.org/ci/computer/${SLAVENAME}/slave-agent.jnlp"
+JENKINS_SLAVE_ROOTDIR="${JENKINS_HOME}/jenkins-slave"
+PID_FILE="${JENKINS_SLAVE_ROOTDIR}/slave.pid"
+SLAVE_LOG="${JENKINS_SLAVE_ROOTDIR}/slave.log"
USER="jenkins"
-SLAVE_LOG="${JENKINS_HOME}/slave.log"
+GROUP="jenkins"
JAVA_BIN="/usr/bin/java"
+if [ ! -f ${SLAVE_JAR} ]
+then
+ echo "Error : ${SLAVE_JAR} dosenot exist, details please refer to README."
+ exit
+fi
+
+[ -e ${JENKINS_SLAVE_ROOTDIR} ] || { mkdir ${JENKINS_SLAVE_ROOTDIR}; chown ${USER}:${GROUP} ${JENKINS_SLAVE_ROOTDIR};};
+if [ ! -d ${JENKINS_SLAVE_ROOTDIR} ]
+then
+ echo "Error : ${JENKINS_SLAVE_ROOTDIR} can not be created! Maybe there is a file with the same name of 'jenkins-slave'."
+ exit
+fi
+
usage ()
{
cat<<EOF
then
echo "jenkins slave is not running!"
else
- echo "jenkins slave is running, pid is $pid"
+ echo "jenkins slave is running, pid is $pid"
fi
}
then
OPTION=$1
else
- echo "None valid argument!"
+ echo "Please input your argument!"
usage
exit 1
fi
status
;;
*)
- echo "$OPTION is not a valid argument!"
- usage
+ echo "Error: $OPTION is not a valid argument"
+ usage
exit 1
;;
esac