温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - Fabric 2 automating deployment error when git pulling on remote server. Repository not found
git python paramiko fabric invoke-command

python - 当git拉远服务器时,Fabric 2自动执行部署错误。

发布于 2020-03-27 15:47:06

我正在尝试使用Fabric 2自动化部署。

当我手动通过远程服务器上的命令行执行git pull时,一切正常。

当我尝试对我的Fabric / Invoke脚本执行相同操作时,它不允许我拖动。

它虽然允许我执行git status和其他命令。

代码:

# Imports
from fabric import Connection
from fabric.tasks import task
import os

# Here i pass my local passphrase:
kwargs = {'passphrase': os.environ["SSH_PASSPHRASE"]}

@task
def serverdeploy(c, branch="Staging"):
    con = Connection('myuser@myhost', connect_kwargs=kwargs)
    with con.cd("/home/user/repository/"):
        # Activate the virtual environment:
        with con.prefix("source ENV/bin/activate"):
            con.run("git pull origin {}".format(branch))

结果是:

git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

笔记:

进行拉动时,我什至没有要求输入密码。

我尝试过在不激活环境的情况下进行拉动,但这也不起作用。


可能是什么问题?

预先感谢您抽出宝贵的时间!

查看更多

查看更多

提问者
Tony Kyriakidis
被浏览
268
Peshmerge 2020-01-27 17:09

请放在con.run("git pull origin {}".format(branch))外面with con.prefix("source ENV/bin/activate"):

您的代码与解释器或虚拟环境无关!试试看,它应该可以工作!