jenkins:一起使用ssh-agent和git插件

所以,我有以下情况:每个项目(例如foo )都有专用用户的服务器,以及作为jenkins用户运行的jenkins服务器。 我为我的foo用户生成了一个SSH密钥对,并将公有的一个作为部署密钥添加到了github回购站。 (我证实我可以用foo用户克隆回购)

在Jenkins中,我使用用户名“foo”和foo的“Global”作用域中的私钥,在“Manage Jenkins”>“Manage Credentials”中将身份validation设置为“带有私钥的SSH用户名”。

所以我configuration了我的Jenkins作业与正确的工作空间 (例如/home/foo/deployment明显拥有用户foo所有权),并使用凭证“foo” 。 对于“源代码pipe理”,我想使用我的回购协议(例如git@github.com:foo / foo.git)的SSHurl。但是,它立即通知我有一个权限问题:

 Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h [email protected]:foo/foo.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

如果我使用URL的https版本( https://github.com/foo/foo.git ),错误消失,但是当我运行作业时,在控制台输出中出现以下错误:

 Started by user developer [EnvInject] - Loading node environment variables. Building in workspace /home/foo/deployment Cloning the remote Git repository Cloning repository https://github.com/foo/foo.git > git init /home/foo/deployment # timeout=10 ERROR: Error cloning remote repo 'origin' hudson.plugins.git.GitException: Could not init /home/foo/deployment [long stacktrace] Caused by: hudson.plugins.git.GitException: Command "git init /home/foo/deployment" returned status code 1: stdout: stderr: /home/foo/deployment/.git: Permission denied [long stacktrace] ERROR: null Finished: FAILURE 

密钥对不使用密码短语,我想添加一个,但如果我首先得到这个工作。 Jenkins运行在Ubuntu 14.04.2 LTS(GNU / Linux 3.13.0-65-generic x86_64)框中。

我在这里错过了什么? 看来我提供的证书没有被使用,这就解释了为什么它在权限上爆炸。 但我不明白他们为什么不被使用? 为什么不能使用git@ URL?

由于它在git init的权限问题上窒息,我在/home/foo/deployment中手动执行了这个操作,但是重新运行Jenkins的作业,它在git fetch又一次出现了权限问题。

啊,是的,我很傻。 SSH用户代理显然只允许jenkins用户连接到远程repo作为foo ,但不授予它写入本地文件系统的权限…