Integrating GIT repository with Jenkins - github

When I am trying to give the Git URL in Jenkins source code management, I am getting this error:
Failed to connect to repository : Error performing command: git.exe ls-remote -h https://github.com/shivnathr/DevOPS1 HEAD
How can I avoid it?

Make sure your Jenkins is running as your account, and not as a service with a technical account.
That way, Jenkins will benefit from the same configuration as your account.
But first, check if you can, with your account, in a simple CMD shell session, execute that same command successfully:
git.exe ls-remote -h https://github.com/shivnathr/DevOPS1 HEAD

When you configure this in Jenkins, it gives this error. But if you ignore this error, does it then work for the build? Have you configured git tools in Jenkins? I am not sure if having git in the path for the user running Jenkins will work (it might), but if you configure a git tool, it should use the first tool in the list to find git. BUT, if the first tool is set to auto-install, then this problem can occur. Make sure the first git tool is just pointing to an installation on the machine. I believe this is a bug. I found this on one of my installations, but I have yet to open an issue for it.

Related

Git bash win32exception: Failed to write credentials

I've recently started using GitHub but for some reason every time I attempt to pull or push it asks for my credentials. I'm 100% sure I have my credentials correct but git bash keeps giving this error:
fatal: Win32Exception encountered.
Failed to write credentials
I don't know why but it does work every time I reinstall git bash up until my next reboot.
Please ask for any information you might need because I'm still quite unfamiliar with git.
Check if you have set a credential helper with git config -l|grep credential
On Windows, you should make sure you have:
git config --global credential.helper manager
With recent Git for Windows, that does use the Microsoft Git Credential Manager, linked to the Credential Manager in Windows.

How to use git lfs with Visual Studio Team Services hosted build agents

I use git lfs to store the large files of my git repo. I then try to build this repo with hosted agents. My build is pretty simple. It has a single task: Execute PowerShell. In the invoked script, the first thing that I want to do is to fetch my lfs dependencies. I therefore have the following in my script:
& git lfs fetch
Unfortunately, my build fails with the following error:
2016-03-04T19:49:05.7021988Z ##[error]git: 'lfs' is not a git command. See 'git --help'.
2016-03-04T19:49:05.7031986Z ##[error]Did you mean this?
2016-03-04T19:49:05.7041987Z ##[error] flow
Since I can't install anything on hosted agents, how am I supposed to have git lfs available?
EDIT
In this issue, I am not talking about git lfs authentication problems as described here. I am strictly talking about the issue of calling git lfs.
Once you are able to call git lfs, look at this answer to solve the authentication problem.
Git LFS is now supported by default on the Hosted Build Controller. But you do need to enable it in your get sources step.
You get this error message because git-lfs isn't installed on Hosted Build Agent by default.
And since you are using Hosted Build Agent, it would be a little troublesome to install git-lfs via Chocolatey on it as you don't have administrator permission. An alternative way would be download the binary files for git-lfs directly and upload it into Source Control. Then you can invoke the git-tfs.exe with an absolute path in your script.
Here are some more details around the solution provided by Eddie. git lfs is not a built-in command. It is a git custom command.
When you call git lfs, git.exe does not know about the lfs command. So it looks in the PATH environment variable and searches for a program named git-lfs.exe. Once found, it calls that program with the provided argument.
So calling git-lfs.exe pull is equivalent to calling git.exe lfs pull.
The solution suggested is therefore to download git-lfs.exe, add it your git repo (it should obviously not be tracked by LFS), and call git-lfs.exe.
It is also possible to add the folder that contains git-lfs.exe to your path environment variable. This makes it possible to use commands like git.exe lfs pull as you usually do.
If you are allowed to install software and have internet access during build you might be able to install git-lfs using the Chocolatey package in a cmd / PowerShell task prior to your git-lfs operation.

Unable to integrate Github with Pycharm

I have created a repository on Github. I am using Windows 7 64 bit and Pycharm Community edition. I want to integrate the Github repository with pycharm but I am getting the error
Couldn't get the list of GitHub repositories
Connect to api.github.com:443 [api.github.com/192.30.252.127] failed: connect timed out
Although I am able to clone he same repository from command prompt using git clone command.
I had the same issue.
Configure your proxy if using one:
File->Settings->System Settings->HTTP Proxy
Another thing to try is to clone the project locally then add as new project in Pycharm. Afterwards I was able to do all git operations under VCS->git including add/commit/push for my project.
try to check whether you have given the path to Git executable correctly by testing it using test button next to it...(file>settings>version control>Git>path to Git Executable)
make sure you have given the git client path correctly..
C:\Program Files\Git\cmd\git.exe

How do I execute a post-receive hook on msysgit on Windows hosted by Apache?

I'm setting up a Git server on a Windows host. I have installed the latest Apache, and have it working with msysGit. I'm not using SSH at all; I can push and pull through HTTP.
Now I want to add a post-receive hook to notify my build server, but I can't figure out how to do that. I see the sample hook scripts in the repository on the server, but I'm confused about what to do there. Do I put a Windows batch file there, named post-receive.bat, or do something else?
I'm a bit fuzzy on details of what this is all doing, but Apache is executing c:\Program Files\git\libexec\git-core\git-http-backend.exe when it sees a Git URL. Is git-http-backend.exe going to trigger the post-receive hook?
Update
I'm getting closer. Here's my hook, in hooks/post-receive in my repo:
#!/c/Program Files/Git/bin/sh
curl http://mybuildserver:8080/job/Whazzup/build
I changed the shebang from #!/bin/sh because on Windows I don't have that. Now in the Apache error log I get the message error: cannot spawn hooks/post-receive: No such file or directory
Incidentally, Git bash's chmod does not seem to work. But I was able to get the permission on post-receive to rwxr-xr-x by renaming the sample file.
Update
I changed the shebang line back to #!/bin/sh, but I still get the same error in the Apache error log: error: cannot spawn hooks/post-receive: No such file or directory. As a test I opened a Git bash prompt in the hooks folder, and executed the hook with ./post-receive, and it worked.
Update
Now I'm wondering if I have a different problem. Taking VonC's advice, I tried running Apache httpd from the command line under my own account, instead of as a service under LocalSystem. Still the same thing. Pushing and pulling work fine, but the hook doesn't execute. Then I tried getting Apache out of the equation. From a Git bash prompt on the same computer as the repo, I did a clone (via filesystem), modify, commit, and push. But the hook still didn't execute.
Update
OK, I had a silly problem in my hook script, but now at least it executes when I push to the repo from the same computer (via filesystem). But not when I push through Apache. Apache is now running under a regular account, and the Apache account has full control of the repository. The push works fine, but the post-receive hook doesn't execute.
Apache is executing c:\Program Files\git\libexec\git-core\git-http-backend.exe when it sees a Git URL. Is git-http-backend.exe going to trigger the post-receive hook?
No, it will pass the command (clone, push, pull) to git itself.
The post-receive hook will be executed after the push has been completed, and it is a bash (unix shell) script, as illustrated in " post-receive hook on Windows - GIT_WORK_DIR: no such file or directory ".
See also " git windows post pull " to see where you can create that post-receive script (in the .git/hooks of your repo): it has nothing to do with your http Apache service in front of the repos.
Regarding the error message "cannot spawn hooks/post-receive: No such file or directory", you can refer to " msysgit error with hooks: "git error: cannot spawn .git/hooks/post-commit: No such file or directory" ":
The shebang must be #!/bin/sh
Apache must run as a regular user instead of Local System, in order to benefit from the environment variables defined for said regular user.
<path_to_git>\bin must be in the PATH

Github Integration with Hudson CI

What I have done so far:
Deployed a tomcat6.0 server to c:\www
Downloaded and deployed the Hudson.war in the c:\www\webapps folder
Installed the Github plugin
Created a private repository on Github
On the server, with hudson installed, generated ssh keys.
Environment variable %HOME% is set to c:\Documents and settings[username] (there is a .ssh directory in there with the keys)
Environment variable %HUDSON_HOME% set to c:\www\webapps\hudson
In hudson I have the following configurations:
Github Project: https://github.com/[my organization]/[project name]
Source Code Management: Git
URL of Repository: git#github.com:[my organization]/[project name].git
Branch specifier: **
Repository Browser: (Auto)
When I run a build, and click the console output link I see this --
Started by user anonymous
Checkout:workspace / C:\www\webapps\hudson\jobs\[project name] (git)\workspace - hudson.remoting.LocalChannel#2e8f6d20
Using strategy: Default
Checkout:workspace / C:\www\webapps\hudson\jobs\[project name] (git)\workspace - hudson.remoting.LocalChannel#2e8f6d20
Fetching changes from the remote Git repository
Fetching upstream changes from git#github.com:[organization name]/[project name].git
... at which point it hangs. When I cancel the build, the following are added --
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
ERROR: (Underlying report) : Error performing command: git.exe fetch -t git#github.com:[organization name]/[project name].git +refs/heads/*:refs/remotes/origin/*
null
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$3.invoke(GitSCM.java:796)
at hudson.plugins.git.GitSCM$3.invoke(GitSCM.java:754)
at hudson.FilePath.act(FilePath.java:756)
at hudson.FilePath.act(FilePath.java:738)
at hudson.plugins.git.GitSCM.gerRevisionToBuild(GitSCM.java:754)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:540)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1180)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:506)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:422)
at hudson.model.Run.run(Run.java:1362)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:145)
First off, since you are starting off with a new CI instance, I would highly recommend that you install the Jenkins fork instead (since it is actively maintained by most of the original developers of Hudson).
Secondly, install the DumpInfo Wrapper plugin and re-run the build again. This plugin prints the system properties and environmental variables in effect during the build and allows you to verify them.
Update:
That plugin should log the system properties and environmental variables, I am surprised you do not see them. As for the passphrase, I suggest you generate a separate private key (from your existing pair) that is not passphrase-protected instead, otherwise you may need to consider the solution offered for: Why git can't remember my passphrase under Windows. I have verified that it works (when I set up my own CI on windows) but I don't feel it is worth the trouble (there are other nuances including installing and running the tomcat instance as the currently logged in user, and NOT as local service, so that pageant will work with it properly), hence I would recommend the first option.
In my case it turned out to be the problem with Git client: I was using v1.6.0 which was triggering
fatal: https://github.com/dmak/jaxb-xew-plugin.git/info/refs download error - The requested URL returned error: 403
error message in Hudson. First it looked like this issue, but strace analysis of git run shown that is was Nginx WebServer (which GitHub is running on) returning 403, not the proxy.
When I've updated to v1.7.3 the problem was gone. So general advise: don't use old clients with GitHub.
P.S. I have tested the cloning both with "Branch Specifier (blank for default): origin/master" in Hudson job configuration and also with blank (default): in both cases Git was able to discover the master branch (origin/master) correctly and used it for cloning.