I'm trying to configure the git repository in Jenkins, I followed all steps on github documentation but I had the bellow error on my application .
I've configured the agent, then I put the ssh url on jenkins.
I've configured the ssh on github as well.
Failed to connect to repository : Command "git ls-remote -h -- git#github.com:user/maven-project.git HEAD" returned status code 128:
stdout:
stderr: git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists
The issue was solved that way
In windows, Jenkins will use the the SSH key of the user it is running as, which is located in the %USERPROFILE%.ssh folder ( on XP, that would be C:\Documents and Settings\USERNAME.ssh, and on 7 it would be C:\Users\USERNAME.ssh). Therefore, you need to force Jenkins to run as the user that has the SSH key configured. To do that, right click on My Computer, and hit "Manage". Click on "Services". Go to Jenkins, right click, and select "Properties". Under the "Log On" tab, choose the user Jenkins will run as, and put in the username and password (it requires one). Then restart the Jenkins service by right clicking on Jenkins (in the services window), and hit "Restart".
Jenkins does not support passphrases for SSH keys. Therefore, if you set one while running the initial Github configuration, rerun it and don't set one.
I'm going to say you don't have the credentials configured properly as you did not mention that.
A similar Stack Overflow response is here, for a slightly different worded error. Similar issue here.
The Jenkins site and others have good examples on setting up Jenkins with GitHub.
Related
I'm very new with Jenkins, and I'm trying to learn how to use it. I have setup the Jenkins on my small Windows-based server, and I have another server (raspberry) where I have initialized a small git project. When I try to add this git repository to the Jenkins, it can not connect to it no matter what. Here's what I have tried so far.
I can check, that the connection is working to the git server by using git ls-remote -h ssh://gitserver#192.168.50.152:22/home/gitserver/GitProject/.git command from any computer within the network, and I get a response after giving my password. I have saved this password as a "Username with password" -kind to Jenkins > Manage Jenkins > Credentials. Then, I have selected this from the Credentials drop down, but all I get is this error: "Failed to connect to repository : Error performing git command: git.exe ls-remote -h ssh://gitserver#192.168.50.152:22/home/gitserver/GitProject/.git HEAD"
Interesting part is, that if I try that command given with the "HEAD" at the end, I get just empty line, but no errors. Could this be an indicator to some kind of an issue? Here's a picture of the configuration. Am I doing something wrong? I have SSH authentication right now via password and ssh-public key. I have tried the SSH-public key as a credential, but no luck.
I'm very new to Jenkins, and just starting to learn, but I could not find an answer to this. Many articles were just pointing out how to connect to GitHub project, but I want to connect to this local project sitting on a raspberry pi, as an exercise.
Ok, the issue was with Jenkins and specifically with the SSH plugin it is using to connect. After updating everything, and Jenkins restarted, the connection is now working, and I can confirm this by clicking the "Build Now", and checking the Build log, Jenkins did fetch the info from the Raspberry server, and it is now sitting at the data-folder of this server!
So, for the rest of the people having this issue, try to update all plugins and then restart the Jenkins.
I'm attempting to clone a remote GitHub enterprise repository and am running into the following error after adding my remote repo's URL to the Git Plugin in my Jenkins configuration:
Failed to connect to repository : Command "git.exe ls-remote -h https://<<server>>/M/AS.git HEAD" returned status code 128:
stdout:
stderr: fatal: unable to access 'https://<<server>>/M/AS.git/': Received HTTP code 502 from proxy after CONNECT
Firs of all You Need to setup github with jenkins in below section also
Go to Github --> click on profile dropdown --> settings --> devloper settings --> personal access token -->
generate new token --> select all scopes --> copy the token
Then go to Jenkins --> manage Jenkins --> github settings --> add user --> Select secret text--> paste the token
Then Test the git-hub connection by clicking test button If its Successful the Jenkins will ready to clone the GitHub repository
And also add Webhooks, Integrations & Services in GitHub
Make sure you have generated Git API Token in Git repository and added the same in the Jenkins Credentials.
If the is done, I don't think there will be any issue in connecting Git to Jenkins.
Also you can test if your Git server is able to ping your Jenkins server. (If you are running your own Git and Jenkins).
All the best.
Check your failed job environment variables.
If there is no environment variable named NO_PROXY, set one in the configuration of your JENKINS job:
NO_PROXY=.mycompany.com
Here, I assume your GitHub Enterprise has an URL like myserver.mycompany.com (replace (mycompany.com by your own)
That will avoid Jenkins trying to access the remote server through the proxy.
If you are running from a VM, make sure you install the package 'git-core'.
You must have git installed in the machine where jenkins is running
I had the same issue and for me it helped a restart for the machine where it was installed Jenkins.
I'm using Git-parameter plugin into Jenkins to build specific tag/branches. It was correctly working but now (not sure it's following and update or something) it's failing in a strange way:
If I create a new job (or duplicate a failing one) add the git parameter to retrieve tag (or branch) and my build steps I can build right away. It shows me the full tag list and can build the one I select.
On the second run, when I click "build with parameter" again then no list provided for the tag and with the branch I have this error :
Command "git ls-remote -h ssh://jenkins#192.168.1.200/repo/git/xxx.git"
returned status code 128:
stdout:
stderr: /tmp/ssh3146539705442744984.sh: line 6: ssh: command not found
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Please look at the Log
So it looks like access issue to the git repo but it's working on first run and I still can build same project (so doing a git checkout too) without this git parameter so I assume my git configuration / credentials are ok.
If you have any idea where to look ?
ps: Jenkins is running on the same machine as the repository (a linux)
Jenkins 2.73.2
Git plugin 3.6.2
Git Parameter Plug-In 0.8.1
Thanks,
Nicolas.
There are lots of question on here about Permission denied (publickey) errors when using the Jenkins git plugin.
Can someone explain the authentication flow this plugin uses to check out a repository? I can't find a good description on the plugin page.
I want to just SSH into the build slave, checkout the repository there, then run my job, but clearly that is not how it works.
I guess I could add my credentials to the jenkins master, but I dont want any code there. I want it on my build slave.
Issue has nothing to do with git really. As their documentation states, it relies on git runtime which in its turn relies on system environment when it comes to secure connections. Ssh requires client to have valid key to connect and fails to that message if client does not provide one. Without any additional actions, key is not injected into environment, so client could not provide any valid key.
What you actually can use is ssh agent plugin. That allows to add key to ssh-agent on slave that will be catched up by git.
My repository url was changed so I updated hgrc file with new url. I also updated new url in jenkins job.
Now when I am building the job, it hangs with the following output
-----------------Console Output-------------------
Started by user user123
Building in workspace D:\jenkins\jobs\api\workspace
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" showconfig paths.default
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
And it will never move forward. If i run the same command on cmd
"C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
It works fine with following output
pulling from ssh://repos-url/repos-name
no changes found
But jenkins hangs on this command. Need some help to move forward.
Thank you
It sounds to me more a jenkins configuration question than a mercurial one :)
Are you talking about the identical clone of the repository? Does the jenkins user have read permissions on the repository it pulls from? Is it configured to pull via ssh, too and does it have the necessary ssh credentials? Or, if pulling via http, is hgweb running on the repo or another webserver to support hg?
Also, unless your project is called 'api', the URL looks strange to me: Jenkins (by default) has its clones in /jenkins-home-directory/jobs/projectname/workspace
As I mentioned in my question that I recently changed repository url. The issue was that new server's key was not cached in the registry where jenkins was hosted.
Resolution:
I logged in to the administrator account(same account used by jenkins) on my server through RDP and on the other side I started building the job in jenkins. When the console output came to this line
[workspace] $ "C:\Program Files\TortoiseHg\hg.exe" pull --rev branch
RDP window showed me an alert which was
Putty Security Alert
I pressed Yes and I saw jenkins console is now progressing and build was successful after that.