I am setting up Jenkins on a Win 2008 server machine and am having some trouble configuring Jenkins to connect to GitHub. I get the following error:
Command "git.exe fetch -t git#github.com:USER/REPO.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: Permission denied (publickey).
fatal: The remote end hung up unexpectedly
ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:950)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:908)
at hudson.FilePath.act(FilePath.java:758)
at hudson.FilePath.act(FilePath.java:740)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:908)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1184)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:537)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:425)
at hudson.model.Run.run(Run.java:1376)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:175)
Things I Have Checked
The Jenkins service is running under my username.
I changed my SSH key so it no longer has a password.
I have verified my SSH key is valid by executing the same command as Jenkins using msysgit.
Verified all my paths are correct.
Jenkins Configuration Settings
Jenkins 1.418
GitHub plugin 0.5
Git plugin 1.1.9
msysgit Works but CMD Prompt Does Not
When I navigate to a valid repo and execute the command from the DOS prompt, it also fails.
Do you have any idea what I may be missing?
Thanks for your help.
As I commented, specifying the HOME environment variable is key, when using ssh protocol.
Since Windows doesn't have a HOME, you need to define it explicitly, to whatever directory you want.
However, Vestnik comments:
I've specified to override HOME on the windows slave node to point it to C:\jenkins.
I've put correct id_rsa under the C:\jenkins\.ssh but still have this issue.
My slave agent running as service under SYSTEM account.
Similar issue: "Problem with Hudson + Git + Gitosis on windows"
Similar resolution: "Problem with Hudson + Git + Gitosis on windows"
Two advices:
you need to make your slave display 'set' in order to check if HOME is defined when used with the SYSTEM account.
If it is not, that may mean you need to add that variable to the "system environment variables", not the "user environment variables".
Don't forget to have both id_rsa and id_rsa.pub in the %HOME%\.ssh directory: you need both public and private ssh keys. (as mentioned in "git clone with ssh issue")
If you have a parametrized build, you also can define HOME that way and check if your slave picks up the right value for HOME:
There are two plugins in jenkins related to ssh that can be used: Publish Over SSH and Jenkins SSH plugin.
The first plugin gives the availability to set a global ssh key and the second plugin gives the availability to set various ssh keys.
Next you need to install two more plugins that will be used in the project configuration GitHub Plugin and Jenkins Git Plugin.
The GitHub plugin will be used to set the GitHub project.
The Jenkins Git plugin will be used to set the "URL of repository" and other things like a branch etc.
All the plugins are available from the tab available in the Jenkins Plugin Manager.
Copied from my blog post, on the topic:
Jenkins configuration:
The Jenkins SSH plugin give the availability to set private key per host, the second plugin do the job for a global host.
If Jenkins SSH plugin is used, then in SSH remote hosts write the host, user, passphrase and the path to the private key.
If Publish Over SSH is used, then in SSH setting write the passphrase and paste the private key or write the path to it.
The project configuration is:
GitHub Project https://github.com/GitUser/iOS-project/
*Source Code Management
-> Git
-> -> Repositories
-> -> -> URL of repository: git#github.com:GitUser/iOS-project.git
-- It is up to you configure a branch or take the default one --
*Build Triggers
-> Poll SCM -- Seted --
-> Schedule: * * * * *
*Build
-> Executed Shell
-> -> Command: xcodebuild -target iOS-project -configuration AdHoc -sdk iphoneos5.0 clean
-> -> Command: agvtool new-version -all $BUILD_NUMBER
-> -> Command: xcodebuild -target iOS-project -configuration AdHoc -sdk iphoneos5.0
-> -> Command: xcrun -sdk iphoneos5.0 PackageApplication -v $WORKSPACE/build/AdHoc-iphoneos/iOS-project.app -o $WORKSPACE/build/AdHoc-iphoneos/iOS-project-$BUILD_NUMBER.ipa PROVISIONING_PROFILE="<provisioning profile>"
-> -> Command: curl http://testflightapp.com/api/builds.json -F file=#$WORKSPACE/build/AdHoc-iphoneos/iCushion-1.0-$BUILD_NUMBER.ipa -F api_token=<api_token> -F team_token=<team_token> -F notes="This is an autodeploy build from Jenkins!" -F notify=True -F distribution_lists="<distributedlist 1>, <distributedlist 2>"
It appears the git plugin now provides a way to point Jenkins to the home directory.
Click the credential add button.
Point Jenkins to your private key.
Select the newly-added credentials from the list.
In my environment (Jenkins 64-bit with Java 32-bit, running in a Windows Server 2016 64-bit), the solution was put the key in the C:\Windows\SysWOW64\config\systemprofile\.ssh folder. According to the Git Plugin documentation:
By default, the Jenkins Windows installer sets up Jenkins to run as a service on Windows, which runs as the “Local System account”, NOT your user account. Since the “Local System account” does not have SSH keys or known_hosts set up, “git clone” will hang during the build. It's possible to keep Jenkins running as the “Local System account” and clone repositories via SSH by making sure that the “Local System account” is set up with a properly configured .ssh directory (i.e. id_rsa, id_rsa.pub, AND known_hosts)
Related
Tried with the configure option, not able to find the tools
configuration option and the git executable section. Seems like it
occurs after a successful build only. Please help.
Here's the output I receive after building the project on the console output section:
Building in workspace C:\Users\Anishas\.jenkins\workspace\Sample123
Cloning the remote Git repository
Cloning repository https://github.com/AnishaSalunkhe/HelloWorld.git
> C:\Users\Anishas\git init C:\Users\Anishas\.jenkins\workspace\Sample123 # timeout=10
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init C:\Users\Anishas\.jenkins\workspace\Sample123
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:656)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:463)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1057)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1097)
at hudson.scm.SCM.checkout(SCM.java:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1738)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Caused by: hudson.plugins.git.GitException: Error performing command: C:\Users\Anishas\git init C:\Users\Anishas\.jenkins\workspace\Sample123
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1726)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1695)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1691)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1321)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:654)
... 12 more
Caused by: java.io.IOException: Cannot run program "C:\Users\Anishas\git" (in directory "C:\Users\Anishas\.jenkins\workspace\Sample123"): CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:240)
at hudson.Proc$LocalProc.<init>(Proc.java:212)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:815)
at hudson.Launcher$ProcStarter.start(Launcher.java:381)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1715)
... 16 more
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 22 more
ERROR: null
Finished: FAILURE
This wasted so much time on my Jenkins Windows slave.
I knew git was in the path because I executed "where git" in the build job's batch command.
where git
C:\Program Files (x86)\Git\cmd\git.exe
Apparently the Jenkins Git Plugin executes ** before ** the environment is inherited.
SET YOUR SLAVE's PATH to Git ( Just DO IT !! )
1) Go to your Windows slave configuration
Manage Jenkins > Manage Nodes
2) Select your slave configuration
3) Check Tool Locations under Node Properties
4) Enter complete path to git executable including git.exe
[x] Tool Locations
Name: (GIT) git
Home: C:\Program Files (x86)\Git\cmd\git.exe
See screenshot:
Go to Manage Jenkins / Global Tool Configuration and set Path to Git executable:
set the path to git.exe and not only to the directory of the git file in both the locations of tool configurations.
Check for below command in Jenkins Server in linux Env:
`whereis git`
you will get the path like /usr/bin/git
Place it in Manage jenkin>Global Tool Configuration> under git path mention /usr/bin/git
Rerun job again
Sometimes this error occurs when disk space is less. so do check the space of your machine where jenkins is hosted. :)
If anyone is using Jenkins with freshly installed Xcode, you'll need to agree to the license using sudo xcodebuild -license or agree through UI.
There can be multiple reasons for that
Check the Permission of the Folder or the Worker Node, In my case 3rd one was the issue because of not providing permissions to the users and groups. As a result you may need to do
sudo chown -R user:group folderName
Check you have configured the SSH Key, if you are using Private Repo from GitHub.
Path Must be provided inside Jenkins Global Configuration of Default Git
In my case,
I have installed git on my slave server. Download-git
Run cmd command
where git
and update your git path with exe file like below in Jenkins node configuration.
C:\Program Files\Git\cmd\git.exe
Go to your Windows slave configuration, Manage Jenkins > Manage Nodes > Select your slave > configure
Check "Tool Locations" under "Node Properties" and give the full path what you got from 'where git' command and save.
yes I have faced the same issue on the Linux ec2 instance but I fixed it through
First of all on your server run the below command, and this command will return to you
$ which git
this command will return to you the actual path of the git, where your git is installed like that /usr/bin/git copy this path.
open your Jenkins > go to manage Jenkins >Global tool configuration > paste the in this field "Path to Git executable
Windows:
1. Install git in windows machine
2. The git.exe path is C:\Program Files\Git\cmd\git.exe (by default, unless you change during installation)
3.Now need to show the path of git.exe in Jenkins git plugin tool
a)manage Jenkins>Global Tool Configuration>Git
b)Add git : name: anything and Path:C:\Program Files\Git\cmd\git.exe
4. Then build for clone. Should be ok
Linux CentOS7:
Same error message I got and after installation git in same machine were Jenkins installed, it is solved.
yum install git
Then you need to follow below steps. Hope so this may be useful for you to resolve your problem.
If your master is linux machine and slave is windows machine...
Pre-Requisites:
your slave machine should have same java version(jdk 1.8).
Git should be installed on your slave machine.
Steps to follow:
Go to your Windows slave configuration Manage Jenkins > Manage Nodes
Select your slave configuration
Check Tool Locations under Node Properties
Enter complete path to git executable including git.exe
Tool Locations
Name: (GIT) git
Home: C:\Program Files (x86)\Git\cmd\git.exe
See screenshot:
1) Make sure the git.exe has executable permissions.
2) Make sure git is configured correctly to refer in Global Tool configurations and also on the Jenkins agent (windows in your case) where you running the job, environment variable for git.exe executable is set correctly
have this problem after my company move to 2FA (2 factory authentication) at GitHub
in the Jenkins I get in credential this
to fix it
I create a personal access token in Github from here
2)after that i get to the same place in the jenkins when the errors ->Credential->add ->jenkins
and get as you see in the picture down
username= what you want name
password = token that you get
Upgrading all plugins and Jenkins to 2.332.1 solved for me
This answer may sound like a joke, but it resolved the exact error message we were getting for only 1 pipeline:
Check if the pipeline has a parameter with no name value.
Don't forget to Add your deploy key credentials (the deploy key attached to the github project) in jenkins (http://yourjenkinsurl:8080/credentials/)
I am using Jenkins in our builds
So I am already using the GIT Plugin
This plugin lets me specify Jenkins credentials, where we have already specified and installed/setup SSH keys.
However at the end of the build, I'd like to git tag my repo. I am calling the git.exe command line, and I get this error on a push:
Permission denied (publickey).
fatal: Could not read from remote repository.
Ideally, we don't want to use another plug in, (e.g. Git Publisher), as we are trying to do more of this via our own scripts as there is a good possibility that we may not use Jenkins in the future.
Also, ideally, we don't want to install items on our build server if we don't have to.
So the question is - how can I specify ssh keys/credentials on the command line for the given 'session'?
Thank you.
Put this in a shell script:
ssh -i path-to-your-private-key
Set the path to the shell script in GIT_SSH for Jenkins. git pull will then use that instead of plain ssh to access the remote repository.
Alternately you could configure ssh in $HOME/.ssh for the account under which Jenkins runs, but that can get tricky if your Jenkins runs as a Windows service.
I need to run a bash script that periodically deletes old git branches. I am having trouble finding a way to connect to the git repo via the execute shell option.
Currently I am using cygwin in order to run git commands. Here is what I have in execute shell:
#!c:\cygwin64\bin\bash --login
git ls-remote git#10.1.1.126:/external-web/collette-com.git
This command is throwing the following error.
[Delete Branches] $ c:\cygwin64\bin\bash --login
C:\Users\tbraga\AppData\Local\Temp\hudson5750784484659728632.sh
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Build step 'Execute shell' marked build as failure
I have tried running this command in the command line and am prompted for a password. Could this be the issue?
I have the git plugin configured within Jenkins and the connection works perfectly when using Source Code Management Git.
Any suggestions on how to make this connections work in the execute shell field would be greatly appreciated.
I solved this problem by passing my credentials to my execute shell script through the Credentials Binding Plugin in Jenkins
It's simple enough to create an SSH key associated with your user.
Try here : https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html
Put keys under %userprofile%/.ssh and try running it again.
You can also use the same credentials used in your Jenkins configuration
I use SSH keys for auth to Github and had this same issue. My Jenkins configuration has EC2 slaves, so the default SSH key on the machine wasn't correct for Github.
I fixed it with the SSH Agent Plugin. In the job, enable the "SSH Agent" setting and choose the stored SSH key for Github authentication. It should be the same one selected for the Git-SCM configuration used to clone the repo.
I need some help here, It's been a week I'm with this problem, can't figure out what's going on. I'm not able to clone a git repo from a slave node (Jenkins). I added the ssh key, host and slave (I've already tried generating a single key and one for each virtual and host)).
On Jenkins:
url:git#github.com: < repo>
Credentials: Here I tried with username/password, username with ssh file, username with ssh key directly, and -none-.
It doesn't seems like there is an authentication problem since I can clone the repo manually from console (both, slave and host). I can also connect with
ssh -T git#github.com
so the ssh key is fine, but when I build, this appear on console:
Building remotely on IE10Win7 in workspace C:\Users\IEUser\Desktop\<
folder >
Wiping out workspace first.
Cloning the remote Git repository
Cloning repository git#github.com:< repo>.git
git init C:\Users\IEUser\Desktop\< folder> # timeout=10
ERROR: Error cloning remote repo 'origin'
ERROR: Error cloning remote repo 'origin'
Performing Post build task...
Does anyone have an idea? Hope someone can give me a clue, Thanks!
I fixed this problem by setting the slave node tool path, selecting git and setting its value to
C:\Program Files (x86)\Git\bin\git.exe
Location: Configure Node - Tool Locations
I recently updated several jenkins plugins and had this problem after the updates. Rolling back the git plugin didn't help, but I did a few other things to get it working. I listed all three here, but it was probably (2) that fixed the problem. Apparently the git executable was reset to default. So, configuring the git executable within the specific project was probably all that was needed. However the other items might come in handy too.
(1) The default git on a jenkins linux install geenrally points to /usr/lib... You need to specify a separate GitForWindows that points to the windows version:
Manage Jenkins
Configure System
Under Git - Git Installations
Add Git -> Git
Give it a name to be referenced in projects
(mine is WindowsGit)
Set Path to Git Executable
(mine is "C:\Program Files (x86)\Git\bin\git.exe")
(for recent git the path is "C:\Program Files\Git\bin\git.exe")
(2) Configure git on the specific project:
Select the project
Select Configure
Under Source Code Management - Git
Select Git Executable as configured in 1)
Set credentials or add new (ssh keys, etc)
(3) Updating the jenkins slave service to run as a specific user:
Go to Windows Services on the slave -- StartMenu, type "services"
Select the Jenkins Slave service in the list on the right
Right-click and select "Properties" of the Jenkins Slave service
Select the "Log On" tab
Update the username and password used in manual tests
Domain login can be specificied with <DOMAIN>\<USERNAME>
Local logins just use <USERNAME>
OK to save and exit
Right-click again and select "Restart" to make the changes active.
I found a decent workaround in my case. The git clone command always inherits its process owner, which may make a difference, even if the two owners of Jenkins (SYSTEM) and cmd (USER) seem to have the same rights on your system. All other configurations were identical (keys, knownhosts, Git client version).
So as far as I can see, calling git clone from cmd will succeed because it calls the remote as USER, whereas git clone called from Jenkins may be rejected because it calls the remote as SYSTEM. In Services, where you would typically start Jenkins through the GUI, you can configure the service to run as a different user (right click on service --> Properties --> Log On). I had to put it like USER#DOMAIN, e.g. Jenkins#company.local or so. I'm not sure about how a cmd parameter would look, but I'd expect there to be one.
Also, I don't quite know what difference this workaround makes in the end, because on my Jenkins, SYSTEM and USER are configured to have the same rights across the system and they are of course both recognized as "Jenkins" by remote. Still, it does the trick for me. Deeper insights welcome.
I was facing similar problem and found that I need to add git to my PATH environment variable for a Windows based slave. I think that #dhj suggestion 2 might work as well in this case.
I found this workaround on Jenkins Jira.
In my case, I started getting this exact error after updating Git on some of my build machines (via Chocolatey, using the "git.install" package) from 1.9.4 to 2.5.0. The old 1.9.4 install was a 32-bit package but the new one is a 64-bit one, so the default install location switched from C:\Program Files (x86)\Git to C:\Program Files\Git. I had the 64-bit path configured on the Jenkins master (since it had the newer Git version), but some slaves still had the older 32-bit version installed, so the slaves were attempting to use an incorrect path. I could have overridden the Git path for individual slaves but the cleaner solution for me was simply to upgrade all the slaves to the newer 64-bit version.
I tried most of the above:
Specify git location.
Set service user.
Run as Administrator.
None of it worked. Eventually decided to uninstall git64 and install git32... changed the git path to the new location (in x86 Program Files). And everything worked.
I ran into this issue recently.
We had some items in our PATH EV which we had added when trying to connect Winium and Selenium to our Jenkins instance.
We removed these items, but still Jenkins seemed to be holding on to the values. After a bit of troubleshooting: restarting Jenkins; restarting the Jenkins server; setting the EVs at the node level; etc., we restarted the Jenkins JNLP service on the Windows slave.
And they lived happily ever after.
I also got the same error and fixed by adding a git path in the "Manage Jenkins -> Global Tool Configuration".
In my env, The windows Jenkins master run a job on the ubuntu slave machine, the master machine has used the default git ('C:\Program Files\Git\git.exe') path and the slave machine has used the git ('/usr/bin/git') path, therefore, I configured slave git path into the master configuration '/usr/bin/git' and its start working for me
I get this error when configuring git repo in a new jenkins project:
Failed to connect to repository : Error performing command: ls-remote -h file:///c:\Dev\git\rx HEAD
I have a local git repo on my windows machine and cloning the same path from command prompt works on the same machine. I don't know what could be the problem (git.exe is on system path)
Windows installs Jenkins as a service. But it runs the Jenkins service under different user permissions that don't have access to GIT. You can follow this link to find the user that Jenkins runs under. http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
For example. My local user name on my windows is "nathandrewsire", exclude the quotes. Open windows services manager (either cmd and c:\services.msc, OR use windows key + R). Enable Log On > This account:. Then type in .\username (e.g. .\nathandrewsire). Then restart the service and you will have access to GIT from Jenkins builds.
I also found a snippet for windows shell command that will output the user to verify it.
echo %PATH%
echo %USERDOMAIN%\%USERNAME%
http://antagonisticpleiotropy.blogspot.com/2012/08/running-jenkins-in-windows-with-regular.html
Linux
If you're using Linux, this error can also be caused from not enabling share on your Git repo. Linux jenkins user won't be able to access Git report under another user unless....
git --bare init --shared=group
Also, your jenkins user and Git repo user must belong to the same group for file permission access. There's other alternatives to that like messing with umasks and ACL's but setting up a linux group for your two users is the easiest way.
Make sure NOT TO OVERWRITE your Git repo with the bare init command. If you already have a Git repo, you'll need to setup/move to a new one with the shared option. I didn't see a way to convert existing repos to shared because I am guessing the files would all need to be updated?
NOTE***
I used VMWare Workstation shared folders to build on a windows guest. Jenkins needs the following format when entering the Git repo.
//vmware-host/Shared Folders/vm-share/ridcyDevelopment.git/
Unable to get Jenkins and Git to play nice