詹金斯运行phing exectask。 Exectask使用ssh代理转发。没有权限。怎么解决?

时间:2013-01-11 08:42:44

标签: java ssh nginx jenkins phing

出了什么问题

我有一台ubuntu 12.10服务器。

我在同一台服务器上安装了Jenkins和Nginx。

Nginx应该服务器文件的/ var / virtual具有www-data的权限设置:www-data

用户jenkins正在运行Jenkins软件。

enter image description here

这是我用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

我尝试了什么

我用Google搜索,然后看到this github article on ssh agent forwarding

这就是我的尝试。

我作为詹金斯进入我的服务器。

然后我输入

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文件中设置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

GOT

Could not open a connection to your authentication agent.

已编辑/etc/ssh/sshd_config并已添加

AllowAgentForwarding yes

选中/etc/ssh/ssh_config。没有ForwardAgent no设置。

再次构建Jenkins作业。失败。

2 个答案:

答案 0 :(得分:2)

我注意到你的git clone命令可能写错了。

检查:

    <exec command="ssh -A ${host-used} 'git clone -b ${environment.branch} ${repository-uri} ${environment.sitedir}${build.time}'"

我换了${environment.branch}${repository-uri}的位置。

参考:git-clone(1) Manual Page

答案 1 :(得分:0)

我建议您使用ant-jsch

我已经在jenkins下使用了ant-jsch。

ant-jsch能够控制ssh识别等等