简体   繁体   English

git clone 在 jenkins shell 脚本中不起作用

[英]git clone not working in jenkins shell script

I am setting up jenkins build pipeline and in one of the build steps, I am trying to git clone a repository.我正在设置 jenkins 构建管道,并且在构建步骤之一中,我正在尝试 git clone 一个存储库。

Build steps(execute shell):构建步骤(执行shell):

git clone git@github.com:orgname/reponame.git

It fails at this step with在这一步失败了

10:14:01 Permission denied (publickey).
10:14:01 fatal: The remote end hung up unexpectedly
10:14:01 Build step 'Execute shell' marked build as failure
10:14:01 Finished: FAILURE

However, while setting up the repo, I have set scm as git and have specified the repository url as git clone git@github.com:orgname/reponame.git and this works perfectly.但是,在设置 repo 时,我已将 scm 设置为 git 并将存储库 url 指定为git clone git@github.com:orgname/reponame.git ,这非常有效。

Any idea what I might be missing here.知道我在这里可能会遗漏什么。

Github uses an ssh public/private keypair for authentication. Github 使用 ssh 公钥/私钥对进行身份验证。 When you use github, you need to provide your public key.当你使用github时,你需要提供你的公钥。 You probably did that once already, following these instructions .按照这些说明,您可能已经这样做过一次。

When you generate a keypair, the default behavior is that only the user which generated the keypair has access to it.生成密钥对时,默认行为是只有生成密钥对的用户才能访问它。 That means if you generate it as upr , the user jenkins has no access to the keypair needed to connect to github.这意味着如果您将其生成为upr ,则用户jenkins无法访问连接到 github 所需的密钥对。

To fix this problem, switch to the jenkins user.要解决此问题,请切换到 jenkins 用户。 If you're in unix, you can do this via如果您使用的是 unix,则可以通过

sudo su - jenkins

Then follow the keygeneration steps provided by github .然后按照github 提供密钥生成步骤进行操作 For Jenkins to use the key, the simplest approach is to create it with no password.对于 Jenkins 使用密钥,最简单的方法是创建它,没有密码。

I've not used it, but a Jenkins plugin like this might allow you to use a password protected keypair.我没有使用过它,但是像这样Jenkins 插件可能允许您使用受密码保护的密钥对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM