Tagged: git

GoCD: Error updating Git material on Windows Server [SOLVED]

Problem

I have a Git material setup that uses a public git repository (private repos are another animal).

<materials>
  <git url="http://mydomain/MyRepo.git" materialName="myrepo.git" />
</materials>

When I trigger the pipeline that uses this material it results in an error.

[go] Start to prepare build/5/Build/1/Build on mygoserver [D:\Go Agents\Internal\1] at Fri Oct 24 08:44:49 EDT 2014
[go] Start updating files at revision b0b18a838a108a208003178fb17e8769edf9587c from
http://mydomain/MyRepo.git
Error while executing [git config remote.origin.url]
 Make sure this command can execute manually.
[go] Job completed build/5/Build/1/Build on mygoserver [D:\Go Agents\Internal\1] at Fri Oct 24 08:44:49 EDT 2014

Error

Looking at go-agent.log I see that there was a problem executing the git command.

…blah blah
2014-10-24 08:27:48,616 [loopThread] ERROR thoughtworks.go.work.DefaultGoPublisher:142 - Error while executing [git config remote.origin.url]
Make sure this command can execute manually.
java.lang.RuntimeException: Error while executing [git config remote.origin.url]
 Make sure this command can execute manually.
  …blah blah
Caused by: com.thoughtworks.go.util.command.CommandLineException: Error while executing [git config remote.origin.url]
 Make sure this command can execute manually.
  …blah blah
Caused by: java.io.IOException: Cannot run program "git" (in directory "pipelines\build"): CreateProcess error=2, The system cannot find the file specified
…blah blah

When I set the material up I got a successful test connection. So an error saying that it can’t find the git command is somewhat perplexing. Does the Git connection test use a different git than the pipeline material processor. When I installed msysgit I manually added the git bin folder to the PATH. I could run git in the command window and on git bash.

Solution

After some hair pulling I decided to re-install msysgit and this time to use the evil option that has the red danger sign.

GitInstallOption

Notice that it says it will override Windows tools, like find.exe and sort.exe. Now, I have to remember that these tools are busted when the server ever has to run a script that needs these. I am not sure of any other changes, but it looks like it is a PATH change. Instead of just having {gitinstall}\bin it also adds {gitinstall}\cmd.

When I restart the Go Server and Agent and try again… IT WORKED!!!

Conclusion

If you are using a Windows Server with Go and you want to use Git Materials, you may need to allow git to override some of your Windows tools and remember that you allowed Git to break said tools when problems arise…and this will arise.

Typing Git Username and Password is Lame

I set up a local Git server to serve as a central repository. Every time I push changes I have to submit my username and password and it got old real quick. I discovered that it is very easy to get around this, although what I am about to share is a little insecure as I am storing my credentials in plain text, but there are ways to secure this.

First a little background. I am using TortoiseGit as my Git client, I am on Windows 7, and my Git server is not exposed to the public internet.

To allow my credentials to be found I first ran this command:

setx HOME %USERPROFILE%

This sets up a Home environment variable on my system that points to my user profile (see this for more info http://technet.microsoft.com/en-us/library/cc755104.aspx).

Then I create a text file named  _netrc in the root of my user profile folder (C:\Users\{yourusername}\_netrc). In the text file I list the machine name, login, and password for each Git server I want to interact with. I assume this could also work for any server that accepts HTTP credentials.

machine mycoolserver
login mysecretlogin
password mysecretpassword
machine someotherhost.com
login mysecretlogin2
password mysecretpassword2

Machine is the root name of the server you are connecting to. In my case I have a local server without a top level domain (no .com). Then you add your credentials. Like I said this is saved in plain text, so you have to be careful with this and make sure you use credentials that you don’t use on any other accounts (e.g. your bank account).

Thanks to StackOverflow and VonC for help on this:

http://stackoverflow.com/questions/6031214/git-how-to-use-netrc-file-on-windows-to-save-user-and-password