Bitbucket管道构建永不结束



这与这个单独的本质上是相同的问题

我有一个位桶管道文件bitbucket-pipelines.yml,它在对main分支进行新的提交时执行文件deploy.shdeploy.sh依次调用pull.sh,后者执行一组操作:

  1. 如果存在,则终止现有的refgator-api.py进程
  2. 更改为包含回购的目录
  3. 从回购中提取
  4. 更改为包含refgator-api.py的目录
  5. 执行python3 refgator-api.py

在最后一步,我的比特桶管道将继续执行(消耗我所有的构建分钟数(。

pull.sh执行了python3 refgator-api.py之后,有什么方法可以成功完成比特桶管道吗?

比特币

image: atlassian/default-image:latest
pipelines:
default:
- step:
script:
- cat ./deploy.sh | ssh -tt root@xxx.xxx.xxx.xxx
- echo "Deploy step finished"

deploy.sh

echo "Deploy Script Started"
cd
sh pull.sh
echo "Deploy script finished execution"

pull.sh

## Kills the current process which is restarted later
kill -9 $(pgrep -f refgator-api.py)
## And change to directory containing the repo
cd eg-api
## Pull from the repo
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.pub"
GIT_SSH_COMMAND="ssh -v" git pull git@bitbucket.org:myusername/myrepo.git
## Change to directory containing the python file to execute
cd refgator-api
python3 refgator-api.py &

这里的关键问题是试图启动并运行python脚本refgator-api.py并关闭会话。

这似乎不可能直接使用shell脚本。但是,可以在远程服务器上使用supervisor

在这种情况下,我安装了监控器apt-get install supervisor,并执行了以下操作:

比特桶管道

image: atlassian/default-image:latest
pipelines:
default:
- step:
script:
- cat ./deploy.sh | ssh -tt root@143.198.164.197
- echo "DEPLOY STEP FINISHED"

部署.sh

printf "=== Deploy Script Started ===n"
printf "Stop all supervisorctl processesn"
supervisorctl stop all
sh refgator-pull.sh
printf "Start all supervisorctl processesn"
supervisorctl start all
exit

Pull.sh

printf "==== Repo Pull ====n"
printf "Attempting pull from repon"
export GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa.pub"
GIT_SSH_COMMAND="ssh " git pull git@bitbucket.org:myusername/myrepo.git
printf "Repo: Local Copy Updatedn"

最新更新