【发布时间】:2012-12-25 19:33:57
【问题描述】:
出了什么问题
我有一个 ubuntu 12.10 服务器。
我在同一台服务器上安装了 Jenkins 和 Nginx。
Nginx 用于服务器文件的 /var/virtual 的权限设置为 www-data:www-data
用户 jenkins 正在运行 Jenkins 软件。
这是我用 phing build.xml 编写的目标
<target name="gitclone">
<echo msg="gitclone ${environment.branch} branch code to ${environment} environment" />
<exec command="ssh -A ${host-used} 'git clone -b ${repository-uri} ${environment.branch} ${environment.sitedir}${build.time}'"
outputProperty="result" escape="false"/>
<echo msg="${result}" />
<echo msg="update all the submodules after gitclone" />
<exec dir="${environment.sitedir}${build.time}" command="ssh -A ${host-used} 'git submodule update --init --recursive'" outputProperty="result" escape="false" />
<echo msg="${result}" />
</target>
这是 jenkins 的控制台输出:
[echo] gitclone master branch code to production environment
[echo] Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
[echo] update all the submodules after gitclone
Execution of target "gitclone" failed for the following reason: /var/lib/jenkins/jobs/abc-master/workspace/build.xml:116:48: '/var/virtual/abc.com/2013_01_11_07_45_35' is not a valid directory
我尝试了什么
我搜索了一下,然后我看到了this github article on ssh agent forwarding。
这是我尝试过的。
我以 jenkins 的身份 ssh 进入我的服务器。
然后我输入了
ssh -T www-data@xxx.xx.xxx.xx
我被提示输入 www-data@xxx.xx.xxx.xx 密码,然后我给出了该密码。注意从现在开始的xxx.xx.xxx.xx指的是同一个服务器的ip地址。
我成功登录为 www-data,所以我退出了 www-data@xxx.xx.xxx.xx。现在以jenkins 用户身份返回服务器。
现在我试试
echo "$SSH_AUTH_SOCK"
我什么都没有。
我进入 /var/lib/jenkins/.ssh/config 并输入以下内容:
Host xxx.xx.xxx.xx
ForwardAgent yes
IdentityFile /var/lib/jenkins/.ssh/id_rsa
StrictHostkeyChecking no
再次构建Jenkins 作业。失败。
然后我想也许我需要在 www-data ~/.ssh/authorized_keys 文件中设置授权密钥,这样每当我们从 jenkins@xxx.xx.xxx.xx 转到 www-data@xxx.xx.xxx 时。 xx,不会提示我输入密码。
所以jenkins,我输入了
cat ~/.ssh/id_rsa.pub | ssh www-data@xxx.xx.xxx.xx 'cat >> .ssh/authorized_keys'
然后我输入了
ssh -T www-data@xxx.xx.xxx.xx
我被提示输入 www-data@xxx.xx.xxx.xx 密码,然后我给出了该密码。
我成功登录为 www-data这次没有提示输入密码,所以我退出了 www-data@xxx.xx.xxx.xx。现在以jenkins 用户的身份返回服务器。
再次构建Jenkins 作业。失败。
作为jenkins,我输入了
echo "$SSH_AUTH_SOCK"
什么都没看到。
试过
ssh-add -L
得到
Could not open a connection to your authentication agent.
编辑/etc/ssh/sshd_config并添加
AllowAgentForwarding yes
检查/etc/ssh/ssh_config。没有ForwardAgent no 设置。
再次构建Jenkins 作业。失败。
【问题讨论】:
标签: java ssh nginx jenkins phing