首页 > 解决方案 > Bitbucket 管道构建永无止境

问题描述

这与此人本质上是相同的问题

我有一个 bitbucket 管道文件,它在对分支进行新提交时bitbucket-pipelines.yml执行该文件。依次调用执行一组操作:deploy.shmaindeploy.shpull.sh

  1. 如果存在,杀死现有refgator-api.py进程
  2. 切换到包含 repo 的目录
  3. 从 repo 中提取
  4. 切换到包含的目录refgator-api.py
  5. 执行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 &

标签: python-3.xshellbitbucketdigital-ocean

解决方案


这里的关键问题是尝试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"

推荐阅读