Groovy, Jenkins, Software Development

Jenkins config.lock .git/config File exists

We can easily resolve virtually every problem in Jenkins. However, that is not true, especially when we do not have administrator access to the host Jenkins runs in. One problem is “Jenkins config.lock .git/config File exists”. This means Jenkins is unable to lock the config.lock file – “Could not lock config file .git/config: File Exists”.

Sample Scenario: Jenkins config.lock – Could not lock config file .git/config: File Exists

Imagine we have Jenkins running in the cloud and don’t have admin access to the host machine. We will likely have admin access to a Jenkins instance but not the host (e.g., EC2 instance). Also, giving admin access in Jenkins is safer and more accessible than direct access to the host.

Fix The Error using Groovy codes

To fix the Jenkins config.lock “Could not lock config file .git/config: File Exists” error, go to the Script console in Jenkins. Then, we list all the files in the host server, specifically under the Jenkins cache directory using the following Groovy script.

Then, we identify the paths to config.lock files that are under the .git directory. Next, we use another Groovy code to delete the config.lock files. Consider the following codes.

In the codes, we specify a path to a config.lock file. We may have many files of this type in Jenkins. If so, delete them one by one carefully. Once we delete all the config.lock files, we can trigger the affected Jenkins jobs again.

Summary

To fix the Jenkins config.lock .git/config File exists or the “Could not lock config file .git/config: File Exists” error, we need a Jenkins user with the right to execute codes in the Script console. Then, we run Groovy codes to list all the files under the Jenkins cache directory in the host server. From the list of files, we can pick out those config.lock files. Finally, delete those config.lock files (one-by-one, for caution) using another Groovy code.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like