fr0zt
fr0zt

Reputation: 881

Git lock in some files

I am working on Linux (bash), where I launch 3 simultaneous jobs (identical at the beginning as they need to check out some code from git) from Jenkins, and sometimes I am getting this error:

fatal: Unable to create '/path/my_project/.git/index.lock': File exists

Each job runs a few git commands like: git reset --hard origin/master;

After analyzing this, I come to the conclusion that, sometimes when a job is running a git command, the other job is tries to use a file which is locked. So I need to implement some strategy for this situation not to occur - to prevent this lock errors.

Any ideas how I could resolve this?

Upvotes: 0

Views: 856

Answers (1)

torek
torek

Reputation: 490128

Don't try to run competing operations in the same repository and/or working tree.

You can attack this problem two ways:

  • do your own job-queueing, so that jobs run sequentially, or
  • use multiple Git working trees and/or clones, so that the jobs are not competing with each other in the first place.

Whether git worktree add will suffice depends on whether your operations are purely working-tree operations.

Note that Jenkins is already a job-queueing system (see Multiple build queues in Jenkins). There are many other options as well. Git is not a job-queueing system; use some external one.

Upvotes: 1

Related Questions