java - Jenkins 运行 phing exectask。 Exectask 使用 ssh 代理转发。没有权限。如何解决?

标签 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

我尝试了什么

我四处搜索,然后我看到了 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 文件中设置 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 作业。失败。

最佳答案

我注意到你的 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

关于java - Jenkins 运行 phing exectask。 Exectask 使用 ssh 代理转发。没有权限。如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14274437/

相关文章:

java - AWT 上格式错误的波斯语字符

java - 用光标、Viewpager 中的数据填充数组

java - 请求作用域的 bean 和数据模型初始化?

java - 无法通过 AssetManager - libgdx 从 zip 存档加载 TextureAtlas

linux - Ubuntu - .ssh 文件夹存在但我看不到它?只能通过终端

nginx - 在 nginx(在 chroot 下)上使用 PHP-FPM 执行不返回任何内容

php - file_get_contents 得到错误的结果

bash - 通过SSH在远程计算机上执行脚本时如何使用源文件

ssh - 如何将公钥对 .pem 文件用于 ansible 剧本?

nginx - macos nginx 配置文件不存在