python-3.x - Bitbucket 管道构建永无止境
问题描述
这与此人本质上是相同的问题
我有一个 bitbucket 管道文件,它在对分支进行新提交时bitbucket-pipelines.yml
执行该文件。依次调用执行一组操作:deploy.sh
main
deploy.sh
pull.sh
- 如果存在,杀死现有
refgator-api.py
进程 - 切换到包含 repo 的目录
- 从 repo 中提取
- 切换到包含的目录
refgator-api.py
- 执行
python3 refgator-api.py
在这最后一步,我的 bitbucket 管道将继续执行(消耗我所有的构建时间)。
pull.sh
执行后有什么方法可以成功完成 bitbucket 管道python3 refgator-api.py
?
bitbucket-ipelines.yml
image: atlassian/default-image:latest
pipelines:
default:
- step:
script:
- cat ./deploy.sh | ssh -tt root@xxx.xxx.xxx.xxx
- echo "Deploy step finished"
部署.sh
echo "Deploy Script Started"
cd
sh pull.sh
echo "Deploy script finished execution"
拉动.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 &
解决方案
这里的关键问题是尝试refgator-api.py
启动并运行 python 脚本并关闭会话。
这似乎不可能直接使用 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 processes\n"
supervisorctl stop all
sh refgator-pull.sh
printf "Start all supervisorctl processes\n"
supervisorctl start all
exit
拉动.sh
printf "==== Repo Pull ====\n"
printf "Attempting pull from repo\n"
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 Updated\n"
推荐阅读
- jquery - 在 jQuery 中从具有相同 CLASS 的不同字段中获取数组值并使用 AJAX 将数据发送到 PHP
- r - 如何从不包括部分内容的两列中创建新列?
- wpf - 如何在图像上绘制折线(WPF)
- python - 如何有效过滤熊猫数据框
- c++ - 如何修复错误'没有规则来制作目标 %.o,所有人都需要。停止'
- javascript - 从另一个函数NodeJS中的回调中获取值
- firebase - 正在创建新文档而不是更新
- netbeans - 如何编辑 Makefile 以使其与 NetBeans 远程构建一起使用?
- javascript - 我的组件层次结构的根在哪里?
- flutter - 如何使堆栈内的列可滚动?