3

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 [email protected]: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 [email protected]:orgname/reponame.git and this works perfectly.

Any idea what I might be missing here.

4
  • Jenkins runs as its own user. Did you test switching to the Jenkins user and doing a clone? Commented Sep 15, 2015 at 17:40
  • Switching user in system or for the github account ? Commented Sep 15, 2015 at 17:44
  • 1
    switch to the jenkins user on the system and run the clone command yourself from the command line. You prolly didn't setup the github ssh stuff for that user. Commented Sep 15, 2015 at 18:48
  • 1
    To achieve what @Reck suggest execute su - jenkins as superuser. Commented Sep 15, 2015 at 19:24

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

you prolly want to use sudo su - jenkins: superuser.com/questions/453988/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.