我正在尝试找到制作CD的最简单方法:
以下脚本有效;它通过ssh登录,在守护进程线程中拉出并运行该应用程序,但从不关闭ssh连接。这导致gitlab-runner作业永远无法完成(一个小时后失败)。如何更改行:
ssh root@ipaddress "killall java && cd projects/testproject && git checkout master && git pull origin master && nohup mvn spring-boot:run &"
因此ssh连接已退出?我尝试了各种方法将“退出”放在最后的“&”之后,但是gitlab运行程序要么忽略它,要么根据我的尝试给出错误。这是完整的.gitlab-ci.yml:
- apt-get update -qq
- apt-get install -qq git
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
stages:
- build_and_deploy
deploy_staging:
stage: build_and_deploy
script:
- echo "Building..."
- ssh root@ipaddress "killall java && cd projects/testproject && git checkout master && git pull origin master && nohup mvn spring-boot:run &"
environment:
name: staging
url: test.com
only:
- master