16

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?

Community
  • 1
  • 1
JoshuaF
  • 1,124
  • 2
  • 9
  • 23

4 Answers4

16

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
BlueSun
  • 3,541
  • 1
  • 18
  • 37
user2957741
  • 993
  • 2
  • 11
  • 11
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.)

sonnyb
  • 3,194
  • 2
  • 32
  • 42
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.

Julian Veerkamp
  • 1,694
  • 2
  • 16
  • 20
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'
Nima Marashi
  • 121
  • 5