我有一个运行Capistrano部署的Jenkins构建作为构建后的动作。
从控制台运行Capkinsrano任务作为Jenkins用户非常正常,没有密码提示(我之前在构建和登台服务器上都设置了SSH密钥)。但是,当通过Jenkins运行相同的脚本时,我突然收到密码提示,然后构建失败(没有TTY存在)。
[workspace] $ /bin/sh -xe /tmp/hudson7321493219694918714.sh
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : cap _2.13.4_ deploy
[workspace] $ /bin/sh -xe /tmp/hudson1545664641721322948.sh
+ cap _2.13.4_ deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
triggering before callbacks for `deploy:update_code'
[32m--> Updating code base with checkout strategy[0m
executing locally: "git ls-remote git@my.staging-server.com:my_project.git master"
command finished in 1200ms
* executing "git clone -q git@my.staging-server.com:my_project.git /var/www/staging/my_project/releases/20121029223619 && cd /var/www/staging/my_project/releases/20121029223619 && git checkout -q -b deploy 1fb11d669a6cb5a714d077162305dfcfaba82f01 && (echo 1fb11d669a6cb5a714d077162305dfcfaba82f01 > /var/www/staging/my_project/releases/20121029223619/REVISION)"
servers: ["my.staging-server.com"]
Password: stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
stty: standard input: Inappropriate ioctl for device
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/staging/my_project/releases/20121029223619; true"
servers: ["my.staging-server.com"]
** [deploy:update_code] exception while rolling back: Capistrano::ConnectionError, connection failed for: my.staging-server.com (Net::SSH::AuthenticationFailed: not-specified)
connection failed for: my.staging-server.com (Net::SSH::AuthenticationFailed: not-specified)
POST BUILD TASK : FAILURE
看起来Ruby在运行Jenkins时可能不会选择我的SSH密钥(Net::SSH::AuthenticationFailed: not-specified
)?
有没有人知道这里可能出现的问题?
答案 0 :(得分:7)
我们遇到了类似的事情。 jenkins的登录shell可能已经自动运行了ssh代理,但jenkins为您的部署生成的上下文却没有。
尝试在jenkins脚本中手动启动一个:
# Start the ssh agent. Evaling the output will set the relevant environment
# variables
eval `ssh-agent`
# Add the default keys like id_rsa and id_dsa (or explicitly specify your key,
# if it's not a default)
ssh-add
# Your normal deploy script here
# Save the return value of your script
RETVAL=$?
# Clean up
kill $SSH_AGENT_PID
# Exit the script with the true return value instead of the return value of kill
# which could be successful even when the capistrano portion of the build has
# crashed
exit $RETVAL
希望这适合你!贝壳很烦人。
答案 1 :(得分:-1)
很遗憾,我只是在执行deploy.rb
之前替换了原始cap deploy
,而在我添加set :password, "sshpassword"