Bitbucket 管道构建永无止境

Bitbucket Pipeline build never ends

这与 this individual

本质上是同一个问题

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

  1. 如果存在,则杀死现有的refgator-api.py进程
  2. 切换到包含 repo 的目录
  3. 从存储库中提取
  4. 切换到包含 refgator-api.py
  5. 的目录
  6. 执行python3 refgator-api.py

在这最后一步,我的 bitbucket 管道将继续执行(消耗我所有的构建时间)。

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

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"

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 并执行了以下操作:

bitbucket 管道

image: atlassian/default-image:latest

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

Deploy.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

Pull.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"