17

Git checkout in Jenkins throws the error "Filename too long" and fails, as follows:

hudson.plugins.git.GitException: Command "git.exe checkout -f 2cea7d8eb9185899c01d2ffc86872f584da2e60c" returned status code 1:

stdout:
stderr: error: unable to create file some_long_named_project/src/test/resources/dbunit_test_data/com/some_long_named_directory/data/testInstances_create_dataRequiresData.xml: Filename too long

I've set the longpaths variable in the config file to 'true', as suggested here Filename too long in Git for Windows and here https://sifaserdarozen.wordpress.com/2015/06/25/git-file-name-too-long-error/, but it didn't help.

Is there anything else I can do?

4 Answers 4

17

In order for Git to handle long filenames correctly, core.longpaths=true needs to be enabled. To set this argument you can do the following:

git config --global core.longpaths true
2
  • 1
    "Prepare an environment for the run" checkbox in Jenkins job configuration adds pre-checkout steps
    – klapshin
    Aug 5, 2020 at 10:28
  • @klapshin I see that section, but where and how would this get added in that?
    – Will Lanni
    Aug 2 at 23:10
6

This answer by Saikat worked for me to fix this issue for a Jenkins git checkout.

Steps to follow (Windows):

  1. Run Git Bash as administrator
  2. Run the following command:

git config --system core.longpaths true

Note: if step 2 does not work or gives any error, you can also try running this command:

git config --global core.longpaths true

Read more about git config here.

(EDIT: Note that there's a related answer which suggests to apply the setting specifically to the affected project rather than using the --system or --global flags.)

5

If you run Windows 10 Home Edition you could change you Registry to enable Long Paths.

Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem in regedit and then set LongPathsEnabled to 1.

If you have Windows 10 Pro or Enterprise you could also use Local Group Policies.

Go to Computer Configuration > Administrative Templates > System > Filesystem in gpedit.msc, open Enable Win32 long paths and set it to Enabled.

2

As a workaround I defined a virtual drive for WORKSPACE path in jenkinsfile script:

bat 'subst W: /d || exit 0' //delete the virtual drive if it already exists 
bat 'subst W: "%WORKSPACE%"' 

and later delete it:

bat 'subst W: /d'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.