1. General
2 源码管理(gitee)
这里credentials填的是你码云的登录名和密码,而非令牌
Refspec:
+refs/heads/*:refs/remotes/origin/* +refs/pull/*/MERGE:refs/pull/*/MERGE
3 Build
4 POST steps
5 执行shell
这里贴出代码
#!/bin/bash BUILD_ID=DONTKILLME echo "start execute shell" cd $WORKSPACE/nhorizons-service mvn clean install cd $WORKSPACE/nhorizons-service/$serviceName/$serviceName-impl mvn clean package -Ptest mkdir -p /service/jenkins-tmp-apps/$JOB_NAME rm -rf /service/jenkins-tmp-apps/$JOB_NAME/* echo "$WORKSPACE/nhorizons-service/$serviceName/$serviceName-impl/target/$serviceName-impl-assembly.tar.gz" tar -zxvf $WORKSPACE/nhorizons-service/$serviceName/$serviceName-impl/target/$serviceName-impl-assembly.tar.gz -C /service/jenkins-tmp-apps/$JOB_NAME/ if [ -n "$WORKSPACE" ]; then echo "rm workspace...." rm -rf "$WORKSPACE"/* fi cd /service/jenkins-tmp-apps/$JOB_NAME/$serviceName-impl/bin ./stop.sh ./start.sh
6. shell中的stop和start sh文件
stop.sh
#!/bin/bash cd `dirname $0` BIN_DIR=`pwd` cd .. DEPLOY_DIR=`pwd` CONF_DIR=$DEPLOY_DIR/config SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' config/dubbo.properties | tr -d ' '` if [ -z "$SERVER_NAME" ]; then SERVER_NAME=`hostname` fi PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'` if [ -z "$PIDS" ]; then echo "ERROR: The $SERVER_NAME does not started!" exit 1 fi if [ "$1" != "skip" ]; then $BIN_DIR/dump.sh fi echo -e "Stopping the $SERVER_NAME ...c" for PID in $PIDS ; do kill $PID > /dev/null 2>&1 done COUNT=0 while [ $COUNT -lt 1 ]; do echo -e ".c" sleep 1 COUNT=1 for PID in $PIDS ; do PID_EXIST=`ps -f -p $PID | grep java` if [ -n "$PID_EXIST" ]; then COUNT=0 break fi done done echo "OK!" echo "PID: $PIDS"
start.sh
#!/bin/bash source ~/.bash_profile cd `dirname $0` BIN_DIR=`pwd` cd .. DEPLOY_DIR=`pwd` CONF_DIR=$DEPLOY_DIR/config SERVER_NAME=`sed '/dubbo.application.name/!d;s/.*=//' config/dubbo.properties | tr -d ' '` SERVER_PROTOCOL=`sed '/dubbo.protocol.name/!d;s/.*=//' config/dubbo.properties | tr -d ' '` SERVER_PORT=`sed '/dubbo.protocol.port/!d;s/.*=//' config/dubbo.properties | tr -d ' '` LOGS_FILE=`sed '/dubbo.log4j.file/!d;s/.*=//' config/dubbo.properties | tr -d ' '` if [ -z "$SERVER_NAME" ]; then SERVER_NAME=`hostname` fi PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'` if [ -n "$PIDS" ]; then echo "ERROR: The $SERVER_NAME already started!" echo "PID: $PIDS" exit 1 fi if [ -n "$SERVER_PORT" ]; then SERVER_PORT_COUNT=`netstat -tln | grep $SERVER_PORT | wc -l` if [ $SERVER_PORT_COUNT -gt 0 ]; then echo "ERROR: The $SERVER_NAME port $SERVER_PORT already used!" exit 1 fi fi LOGS_DIR="" if [ -n "$LOGS_FILE" ]; then LOGS_DIR=`dirname $LOGS_FILE` else LOGS_DIR=$DEPLOY_DIR/logs fi if [ ! -d $LOGS_DIR ]; then mkdir $LOGS_DIR fi STDOUT_FILE=$LOGS_DIR/stdout.log LIB_DIR=$DEPLOY_DIR/lib LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr " " ":"` JAVA_OPTS=" -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -Ddubbo.shutdown.hook=true " JAVA_DEBUG_OPTS="" if [ "$1" = "debug" ]; then JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n " fi JAVA_JMX_OPTS="" if [ "$1" = "jmx" ]; then JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false " fi JAVA_MEM_OPTS="" BITS=`java -version 2>&1 | grep -i 64-bit` if [ -n "$BITS" ]; then JAVA_MEM_OPTS=" -server -Xmx256m -Xms256m -Xmn128m -Xss256k -XX:+DisableExplicitGC -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=70 " else JAVA_MEM_OPTS=" -server -Xms128m -Xmx128m -XX:SurvivorRatio=2 -XX:+UseParallelGC " fi echo -e "Starting the $SERVER_NAME ...c" nohup java $JAVA_OPTS $JAVA_MEM_OPTS $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS -classpath $CONF_DIR:$LIB_JARS com.alibaba.dubbo.container.Main > $STDOUT_FILE 2>&1 & COUNT=0 while [ $COUNT -lt 1 ]; do echo -e ".c" sleep 1 if [ -n "$SERVER_PORT" ]; then if [ "$SERVER_PROTOCOL" == "dubbo" ]; then COUNT=`echo status | nc -i 1 127.0.0.1 $SERVER_PORT | grep -c OK` else COUNT=`netstat -an | grep $SERVER_PORT | wc -l` fi else COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l` fi if [ $COUNT -gt 0 ]; then break fi done echo "OK!" PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'` echo "PID: $PIDS" echo "STDOUT: $STDOUT_FILE"
当然,也可以 restart.sh
#!/bin/bash cd `dirname $0` ./stop.sh ./start.sh