在使用 gitlab-runner 搭建 CICD 过程中遇到一直卡住结束不了的问题。在此记录下问题。
重现步骤
- .gitlab-ci.yml
variables:
GIT_CLEAN_FLAGS: none # disable git clean
SERVER_WORK_PATH: "/home/work/app/test"
stages:
- build
- delivery
- deploy
- clean
job_build:
stage: build
only:
- master
tags:
- java
script:
- echo "---------------------------Begin to build---------------------------"
- pwd
- mvn clean package -DskipTests -T4 -Pdev -ff
- echo "---------------------------End of the build---------------------------"
job_delivery:
stage: delivery
tags:
- java
script:
- echo "---------------------------Begin to delivery---------------------------"
- mkdir -p $SERVER_WORK_PATH/test
- cp $CI_PROJECT_DIR/test/target/test.jar $SERVER_WORK_PATH/test
- echo "---------------------------End of the delivery---------------------------"
job_deploy:
stage: deploy
tags:
- java
script:
- echo "---------------------------Begin to deploy---------------------------"
- cd $SERVER_WORK_PATH
- nohup java -jar test.jar >>$PROJECTDIR/nohup.out &
- echo "---------------------------End of the deploy---------------------------"
job_clean:
stage: clean
tags:
- java
script:
- echo "---------------------------Begin to clean---------------------------"
- cd $CI_PROJECT_DIR && mvn clean
- echo "---------------------------End of the clean---------------------------"
原因
在启动 jar 时日志输出方式错误
nohup java -jar test.jar >>$PROJECTDIR/nohup.out &
正确方式
nohup java -jar test.jar >>$PROJECTDIR/nohup.out 2>&1 &
网友评论