Create project

image.png

填写和验证仓库

image.png

选择分支

与功能分支|合作团队城现场 (jetbrains.com)

image.png

Build Step

maven 打包

clean package -DskipTests -Dmaven.javadoc.skip=true

image.png

执行shell 命令上传jar到服务器

%teamcity.build.workingDir%/target/showroom-0.0.1-SNAPSHOT.jar => /test

image.png

执行shell 命令启动jar

mv /root/test/showroom-0.0.1-SNAPSHOT.jar /doc/program/showroom/
cd /doc/program/showroom/
./start-stop-auto.sh

image.png

  • start-stop-auto.sh
  1. !/bin/bash
  2. # PROJECT_PATH=/doc/program/smart/soul-admin.jar
  3. # read -p ":" PROJECT_PATH
  4. # echo "你输入的数是:$PROJECT_PATH"
  5. PROJECT_PATH=/doc/program/showroom/showroom-0.0.1-SNAPSHOT.jar
  6. PROJECT_PORT=9001
  7. PROJECT_PROPERTIES=test
  8. # 设置环境参数
  9. JAVA_OPTS=" -Xms512m "
  10. # -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
  11. JAVA_OPTS="${JAVA_OPTS} -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC "
  12. JAVA_OPTS="${JAVA_OPTS} -Dfile.encoding=UTF-8"
  13. # 设置默认值
  14. if [ ! $PROJECT_PATH ]; then
  15. PROJECT_PATH="test.jar"
  16. fi
  17. if [ ! $PROJECT_PORT ]; then
  18. SERVER_PORT=" --server.port=1234"
  19. else
  20. SERVER_PORT=" --server.port=${PROJECT_PORT}"
  21. fi
  22. if [ ! $PROJECT_PROPERTIES ]; then
  23. SERVER_PROPERTIES="--spring.profiles.active=prod"
  24. else
  25. SERVER_PROPERTIES="--spring.profiles.active=${PROJECT_PROPERTIES}"
  26. fi
  27. # shutdown
  28. pid=`ps -ef|grep $PROJECT_PATH | grep -v grep | awk '{print $2}'`
  29. kill -9 $pid
  30. echo "$pid进程终止成功"
  31. sleep 1
  32. # startUp
  33. sleep 2
  34. # 判断jar包文件是否存在,如果存在启动jar包,并时时查看启动日志
  35. if test -e $PROJECT_PATH
  36. then
  37. echo '文件存在,开始启动此程序...'
  38. # 启动jar包,指向日志文件,2>&1 & 表示打开或指向同一个日志文件
  39. echo "nohup java -jar $JAVA_OPTS "$PROJECT_PATH" $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &"
  40. nohup java -jar $JAVA_OPTS $PROJECT_PATH $SERVER_PORT $SERVER_PROPERTIES >/dev/null 2>&1 &
  41. echo "$PROJECT_PATH 启动成功..."
  42. else
  43. echo "$PROJECT_PATH 文件不存在,请检查。"
  44. fi