Add script of launch slave to OPNFV Jenkins by using JNLP 87/387/3
authorm00133142 <meimei@huawei.com>
Mon, 20 Apr 2015 03:04:56 +0000 (11:04 +0800)
committerm00133142 <meimei@huawei.com>
Mon, 27 Apr 2015 07:43:39 +0000 (15:43 +0800)
JIRA: OCTO-51

Change-Id: Ib4293a15c409f2d9f8a4671094029ba57cdb1cb3
Signed-off-by: m00133142 <meimei@huawei.com>
ci/README
ci/jenkins-slave.init

index a830076..d1bb1b1 100755 (executable)
--- a/ci/README
+++ b/ci/README
@@ -9,16 +9,17 @@
 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.
index 8402b67..35dc2fd 100755 (executable)
@@ -12,27 +12,44 @@ set -o nounset
 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
@@ -74,7 +91,7 @@ status()
     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
 }
 
@@ -82,7 +99,7 @@ if [ $# -gt 0 ]
 then
     OPTION=$1
 else
-    echo "None valid argument!"
+    echo "Please input your argument!"
     usage
     exit 1
 fi
@@ -103,8 +120,8 @@ case "$OPTION" in
         status
     ;;
     *)
-        echo "$OPTION is not a valid argument!"
-    usage
+        echo "Error: $OPTION is not a valid argument"
+        usage
         exit 1
     ;;
 esac