Wednesday, July 1, 2015

Corrupted .git/config Files and Jenkins

For an as-yet-undetermined reason, many job workspaces in my Jenkins server had corrupted config files in their Git clones.  The files weren't piles of binary trash... they were just missing most of their content.  Many of the files just looked like this:

                url = ssh://git@myserver.mydomain.com/myproject/myproject.git

[remote "origin"]

                url = ssh://git@myserver.mydomain.com/myproject/myproject.git


That's it... that's the whole file.  

Thus, when the Jenkins job would fire, the Git steps would crash like so:

FATAL: Repository config file /path/to/jenkins/jobs/MyJob/workspace/.git/config invalid 
Cannot read file /path/to/jenkins/jobs/MyJob/workspace/.git/config
java.lang.IllegalArgumentException: Repository config file /path/to/jenkins/jobs/MyJob/workspace/.git/config invalid 
Cannot read file /path/to/jenkins/jobs/MyJob/workspace/.git/config
at org.eclipse.jgit.lib.BaseRepositoryBuilder.loadConfig(BaseRepositoryBuilder.java:684)
(... more stacktrace ...)

Searches based on the stacktrace didn't find anything helpful.  I had no expectation that the .git/config file itself was in question... I troubleshot as if it was a Jenkins issue that I figured meant bumping up some JVM startup parameter.  When that rabbit hole produced no carrots, it finally hit me to check that config file itself.

Just blowing away the workspace from the Jenkins job page and rerunning the job was enough to clear the problem -- empty workspace means it'll make a new clone, and suddenly all is good.

Lesson:  when the error points at that file, at least make sure the file itself is plugged in and getting power :-)