我正试图通过jenkins工作中的capistrano 3部署到服务器.
"cap environment deploy"完全可以从我的mac中获得我的信誉,但在jenkins下,使用部署信誉,我遇到了一个问题.
最奇怪的是前几个git命令成功,但是当capistrano进入"git remote update"时,服务器挂起时出现"未授权"错误.我通过ssh'ing到服务器并从/ var/www/repo运行'git remote update'来验证这一点.
我有密钥转发设置 - 下面是我的詹金斯工作:
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!
有任何想法吗?
谢谢,
安迪
我在当前部署中遇到了同样的问题.我运行命令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.