简体   繁体   中英

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.

Build steps(execute 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.

Any idea what I might be missing here.

Github uses an ssh public/private keypair for authentication. When you use github, you need to provide your public key. 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.

To fix this problem, switch to the jenkins user. If you're in unix, you can do this via

sudo su - jenkins

Then follow the keygeneration steps provided by github . For Jenkins to use the key, the simplest approach is to create it with no password.

I've not used it, but a Jenkins plugin like this might allow you to use a password protected keypair.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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