Create project
填写和验证仓库
选择分支
Build Step
maven 打包
clean package -DskipTests -Dmaven.javadoc.skip=true
执行shell 命令上传jar到服务器
%teamcity.build.workingDir%/target/showroom-0.0.1-SNAPSHOT.jar => /test
执行shell 命令启动jar
mv /root/test/showroom-0.0.1-SNAPSHOT.jar /doc/program/showroom/
cd /doc/program/showroom/
./start-stop-auto.sh
- start-stop-auto.sh
!/bin/bash
# PROJECT_PATH=/doc/program/smart/soul-admin.jar
# read -p ":" PROJECT_PATH
# echo "你输入的数是:$PROJECT_PATH"
PROJECT_PATH=/doc/program/showroom/showroom-0.0.1-SNAPSHOT.jar
PROJECT_PORT=9001
PROJECT_PROPERTIES=test
# 设置环境参数
JAVA_OPTS=" -Xms512m "
# -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
# 设置默认值
if [ ! $PROJECT_PATH ]; then
PROJECT_PATH="test.jar"
fi
if [ ! $PROJECT_PORT ]; then
SERVER_PORT=" --server.port=1234"
else
SERVER_PORT=" --server.port=${PROJECT_PORT}"
fi
if [ ! $PROJECT_PROPERTIES ]; then
SERVER_PROPERTIES="--spring.profiles.active=prod"
else
SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
fi
# shutdown
pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
kill -9 $pid
echo "$pid进程终止成功"
sleep 1
# startUp
sleep 2
# 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
if test -e $PROJECT_PATH
then
echo '文件存在,开始启动此程序...'
# 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
echo "$PROJECT_PATH 启动成功..."
else
echo "$PROJECT_PATH 文件不存在,请检查。"
fi