Before you instantly mark this as a possible duplicate please read the entire text
TLDR:
I'm trying to set up a jenkins to read a private Github repository. When I use jenkins credentials with username/password it works, when I use jenkins credentials with a private key it does not and I'm getting an "invalid username / or password" error.
Full description:
- I have a jenkins 2.5 installed on apache-tomcat 8, jenkins is running under the user
tomcat8. Credential plugin (2.1.4), Git client plugin (1.19.6), Gitplugin (2.5.2), Github API Plugin (1.76), GitHub plugin (1.19.2), SSH credential plugin (1.12) are also installed. Git is running in version 2.1.4 - I've created an ssh-keypair with empty password for the user tomcat8 [logged in as tomcat8 via
sudo -su tomcat8] - I've added the public key to the private Github repository
- I've created a jenkins credentials
ssh username with private keywith global scope, usernametomcat8, empty password and the full private key from-----BEGIN RSA PRIVATE KEY-----to-----END RSA PRIVATE KEY----- - I'v created a jenkins creditals "username / password" with the plain username and passwort of the github account.
When I log into the user
tomcat8and check the github authentication via shell with the commandssh -T [email protected]I get the correct output. That means my authentication with the key against github works (right?)tomcat8@ci:~/.ssh$ ssh -T [email protected] Hi github-username! You've successfully authenticated, but GitHub does not provide shell access.
Wenn I now setup my jenkins job: repository URL: https://github.com/repoownername/reponame.git and use the username/passwort-credential the access is fine. But when I use the ssh-credentials the authentication failes with
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h https://github.com/repoownername/reponame.git HEAD" returned status code 128: stdout: stderr: remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/repoownername/reponame.git'
Further information When I run a build with the username/password credentials
git config remote.origin1.url https://github.com/repoownername/reponame.git # timeout=10 Fetching upstream changes from https://github.com/repoownername/reponame.git using .gitcredentials to set credentials git config --local credential.username github-username # timeout=10 git config --local credential.helper store --file=/tmp/tomcat8-tomcat8-tmp/git1018128562913260002.credentials # timeout=10 git -c core.askpass=true fetch --tags --progress https://github.com/repoownername/reponame.git +refs/heads/:refs/remotes/origin1/ git config --local --remove-section credential # timeout=10
When I use the SSH credentials I get the the error mentioned above.
So my question is now: How can I successfully use my SSH-credentials instead of Username/Password
Some of the tutorials I checked: