【问题标题】:Issue deploying project via capistrano 3 with jenkins使用 jenkins 通过 capistrano 3 部署项目
【发布时间】:2014-04-18 23:17:41
【问题描述】:

我正在尝试通过 jenkins 作业中的 capistrano 3 部署到服务器。

“cap environment deploy”在我的 mac 和我的凭据下完美运行,但是在 jenkins 下,使用部署凭据,我遇到了问题。

超级奇怪的是,前几个 git 命令成功了,但是当 capistrano 到达“git remote update”时,服务器挂了一个“未授权”错误。我已经通过 ssh'ing 到服务器并从 /var/www/repo 运行 'git remote update' 验证了这一点。

我已经设置了密钥转发——下面是我的 Jenkins 工作:

eval $(ssh-agent)
ssh-add ~/.ssh/keyname.pem
cap staging deploy

我不知道 capistrano 内部发生了什么会导致第一个 git 命令成功('git ls-remote'),但“git remote update”失败。是的,密钥已作为部署密钥添加到 github 上,用于 repo,并且在 deploy.rb 和 ~/.ssh/config 中启用了密钥转发。

以下是来自“cap staging deploy”的示例失败日志,在 Jenkins 盒子上以 Jenkins 用户身份运行:

 INFO [d3e19149] Running /usr/bin/env mkdir -p /tmp/project/ on server.xxxxxyyyy.com
DEBUG [d3e19149] Command: /usr/bin/env mkdir -p /tmp/project/
 INFO [d3e19149] Finished in 0.943 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/project/git-ssh.sh 0.0%
 INFO Uploading /tmp/project/git-ssh.sh 100.0%
 INFO [43533553] Running /usr/bin/env chmod +x /tmp/project/git-ssh.sh on server.xxxxxyyyy.com
DEBUG [43533553] Command: /usr/bin/env chmod +x /tmp/project/git-ssh.sh
 INFO [43533553] Finished in 0.052 seconds with exit status 0 (successful).
DEBUG [40e092d5] Running /usr/bin/env git ls-remote git@github.com:Organization/project.git on server.xxxxxyyyy.com
DEBUG [40e092d5] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/project/git-ssh.sh /usr/bin/env git ls-remote git@github.com:Organization/project.git )
DEBUG [40e092d5]    69a8427388e2958e9b2c67e6048a46cb3a2544a5    HEAD
DEBUG [40e092d5]    69a8427388e2958e9b2c67e6048a46cb3a2544a5    refs/heads/master

DEBUG [40e092d5] Finished in 1.635 seconds with exit status 0 (successful).
 INFO [3d9e0765] Running /usr/bin/env mkdir -pv /var/www/shared /var/www/releases on server.xxxxxyyyy.com
DEBUG [3d9e0765] Command: /usr/bin/env mkdir -pv /var/www/shared /var/www/releases
 INFO [3d9e0765] Finished in 0.046 seconds with exit status 0 (successful).
 INFO [3ef2c63f] Running /usr/bin/env mkdir -pv /var/www/shared/log /var/www/shared/tmp/pids /var/www/shared/tmp/cache /var/www/shared/tmp/sockets /var/www/shared/vendor/bundle /var/www/shared/public/system on server.xxxxxyyyy.com
DEBUG [3ef2c63f] Command: /usr/bin/env mkdir -pv /var/www/shared/log /var/www/shared/tmp/pids /var/www/shared/tmp/cache /var/www/shared/tmp/sockets /var/www/shared/vendor/bundle /var/www/shared/public/system
 INFO [3ef2c63f] Finished in 0.043 seconds with exit status 0 (successful).
 INFO [a0820d89] Running /usr/bin/env mkdir -pv /var/www/shared/config on server.xxxxxyyyy.com
DEBUG [a0820d89] Command: /usr/bin/env mkdir -pv /var/www/shared/config
 INFO [a0820d89] Finished in 0.050 seconds with exit status 0 (successful).
DEBUG [19575759] Running /usr/bin/env [ -f /var/www/shared/config/database.yml ] on server.xxxxxyyyy.com
DEBUG [19575759] Command: [ -f /var/www/shared/config/database.yml ]
DEBUG [19575759] Finished in 0.063 seconds with exit status 0 (successful).
DEBUG [06e522d5] Running /usr/bin/env [ -f /var/www/repo/HEAD ] on server.xxxxxyyyy.com
DEBUG [06e522d5] Command: [ -f /var/www/repo/HEAD ]
DEBUG [06e522d5] Finished in 0.056 seconds with exit status 0 (successful).
 INFO The repository mirror is at /var/www/repo
DEBUG [062dd56a] Running /usr/bin/env if test ! -d /var/www/repo; then echo "Directory does not exist '/var/www/repo'" 1>&2; false; fi on server.xxxxxyyyy.com
DEBUG [062dd56a] Command: if test ! -d /var/www/repo; then echo "Directory does not exist '/var/www/repo'" 1>&2; false; fi
DEBUG [062dd56a] Finished in 0.053 seconds with exit status 0 (successful).
DEBUG [65e9187e] Running /usr/bin/env cd /var/www/repo && git rev-parse --short HEAD on server.xxxxxyyyy.com
DEBUG [65e9187e] Command: cd /var/www/repo && git rev-parse --short HEAD
DEBUG [65e9187e]    69a8427
DEBUG [65e9187e] Finished in 0.080 seconds with exit status 0 (successful).
 INFO [349bd507] Running /usr/bin/env git remote update on server.xxxxxyyyy.com
DEBUG [349bd507] Command: cd /var/www/repo && /usr/bin/env git remote update
DEBUG [349bd507]    Fetching origin
DEBUG [349bd507]    Fetching origin
DEBUG [349bd507]    ERROR: Repository not found.
DEBUG [349bd507]    Fetching origin
DEBUG [349bd507]    fatal: The remote end hung up unexpectedly
DEBUG [349bd507]    Fetching origin
DEBUG [349bd507]    error: Could not fetch origin
cap aborted!

有什么想法吗?

谢谢,

安迪

【问题讨论】:

    标签: git deployment ssh jenkins capistrano


    【解决方案1】:

    我在当前的部署中遇到了同样的问题。我运行命令cap staging deploy --trace 并收到以下输出:

    Command: cd /var/www/deployment directory/repo && (GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/deployment directory/git-ssh.sh /usr/bin/env git remote update )    
    
    DEBUG [520a3953]    Fetching origin   
    DEBUG [520a3953]    Fetching origin  
    DEBUG [520a3953]    ERROR: Repository not found.
    DEBUG [520a3953]    Fetching origin
    DEBUG [520a3953]    fatal: The remote end hung up unexpectedly  
    DEBUG [520a3953]    Fetching origin
    DEBUG [520a3953]    error: Could not fetch origin  
    cap aborted!   
    SSHKit::Command::Failed: git stdout: Nothing written 
    git stderr: Nothing written   
    

    我通过删除部署目录修复了错误

    rm -rf /var/www/deployment directory
    

    我再次运行cap staging deploy --trace 并修复了不相关的 Rails 错误并能够成功部署。

    事后看来,我可能只删除了 /var/www/deployment 目录/repo 并获得了相同的结果。我确定我的问题是我更改了 gitlab 项目名称,并且它存储在部署服务器的 repo 目录中。命令: Command: cd /var/www/deployment directory/repo && ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/deployment directory/git-ssh.sh /usr/bin/env git remote update ) 可能正在使用存储在部署服务器中某个文件中的旧存储库 URL。

    【讨论】:

    • 感谢您的文章——好东西。我最近没有尝试从 Jenkins 工作中运行 cap deploy —— 我有点放弃了。 :) 稍后会回来看看这是否也解决了我的问题。
    • 非常感谢!环顾四周,终于应用了您的解决方案,它奏效了! :)
    • 这是删除旧部署目录的答案。谢谢
    • 这就是答案。删除 ${deploy_dir}/repo 并成功部署。
    • 我反对从我的生产环境中删除任何东西,除非我确切地知道它是什么并且我再也不需要它了。这个答案很好,除了我将 repo 重命名为 repo2 并获得相同的结果
    【解决方案2】:

    我在更改存储库位置时遇到了同样的问题,但没有删除部署目录:

    /www/deployment directory/repo
    

    我在 /www/deployment 目录/repo 中运行了这个命令:

    git remote show origin
    

    这表明源仍然设置为旧仓库,我通过运行以下命令进行了更改:

    git remote set-url origin git://new.url.here
    

    (我从这个问题中了解到:Change the URI (URL) for a remote Git repository

    【讨论】:

    • 这应该是公认的答案。我有点热血沸腾,在没有审查的情况下执行了接受的答案,我希望我能先向下滚动一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 2018-10-08
    • 1970-01-01
    相关资源
    最近更新 更多