I have 4 Ubuntu machines and a Jenkins job runs on them. A shared disk is mounted to them as /data/repositories/. Under it, there are many non-bare repositories created by git clone <url> --no-checkout -b master.
When the job is triggered, it runs these step:
- In
/data/repositories/foo, fetchBranch AandBranch B - Parse
Branch Bhead and get its commitSHA1VALUE - Create a work tree by
git worktree add --no-checkout /path/to/worktree SHA1VALUE - Get the changed files in
Branch Ahead - Enable sparse checkout in
/path/to/worktree - Write the changed files into
/data/repositories/foo/.git/worktrees/xx/info/sparse-checkout - Run
git checkoutin/path/to/worktreeto check out these files - Use
git cherry-pickto applyBranch Ahead ontoSHA1VALUEin/path/to/worktree - Push the new commit to
Branch B.
/path/to/worktree is not on the shared disk but on each machine's own disk. In Step 7 and Step 9, it may occasionally raise an error fatal: not a git repository /data/repositories/foo/.git/worktrees/xx. When the error occurs, /data/repositories/foo/.git/worktrees/xx is not there as if it's been deleted by some process or thread right before the step. In the job, it won't be deleted on purpose until the job is finished or an exception is raised in these steps.
If I rebuild the job with the same parameters, the problem does not occur again.
If /data/repositories/foo/.git/worktrees/xx is not successfully created in the first place, it would be detected during these steps and Step 8 would always fail.
Multiple jobs could run on the same /data/repositories/foo at the same time. But in /data/repositories/foo/.git/worktrees/xx/info/sparse-checkout, the xx part is unique.
Thanks for any clues.