Branch indexing failure in Jenkins

As usual, CI/CD anomalies are always a source for blogging. And also a way of improving the reliability of the CI system. A user has complained of Jenkins branch indexing failure. The branch indexing is a feature of Multibranch pipeline that discover new branches and delete old branches. Instead of index branches, the user got a fancy java stack :-).

java.lang.IllegalArgumentException: Repository config file /home/jenkins/caches/git-46ca6ff4bea60131b71f18bc70a1dd5f/.git/config invalid Cannot read file /home/jenkins/caches/git-46ca6ff4bea60131b71f18bc70a1dd5f/.git/config
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.loadConfig(BaseRepositoryBuilder.java:687)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.getConfig(BaseRepositoryBuilder.java:662)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.guessWorkTreeOrFail(BaseRepositoryBuilder.java:698)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.setupWorkTree(BaseRepositoryBuilder.java:628)
    at org.eclipse.jgit.lib.BaseRepositoryBuilder.setup(BaseRepositoryBuilder.java:557)
    at org.eclipse.jgit.storage.file.FileRepositoryBuilder.build(FileRepositoryBuilder.java:92)
    at org.eclipse.jgit.storage.file.FileRepositoryBuilder.create(FileRepositoryBuilder.java:111)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getRepository(CliGitAPIImpl.java:2336)
    at hudson.plugins.git.GitAPI.getRepository(GitAPI.java:269)
    at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:234)
    at jenkins.scm.api.SCMSource.fetch(SCMSource.java:148)
    at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:294)
    at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:157)
    at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:122)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE

Checking the config file shows a corruption. This file is a classic git file that you have when you clone a repository.

    url = ssh://user@tuleap/repo.git
[remote "origin"]
    url = ssh://user@tuleap/repo.git

The first line shoud be included in a remote section. Having two remote sections in git is common but not for CI usage. I wrote a script to detect broken config:

#!/bin/bash

GIT_CONFIG_FILES=$(find /home/jenkins/caches -mindepth 3 -maxdepth 3 -name config)
i=0
for f in $GIT_CONFIG_FILES ;
do
        FIRST_LINE=$(head -n 1 $f)
        if [ "$FIRST_LINE" != "[core]" ] ;
        then
                echo "------------------------------------------------------"
                echo "Suspicious config file $f"
                head "$f"
                i=$((i+1))
        fi
done
echo "Found $i suspicious files"

Fixing the file is easy.

  • Add the missing lines by reading the beginning of the file in a fresh clone;
  • Remove the first line which is obviously invalid;

The correct config file is:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = ssh://user@tuleap/repo.git

I'm still wondering who has corrupted the files. The strange thing is that JGIT is visible in the stack even if my job was supposed to use the git client configuration.

By @Romain JACQUET in
Tags :