Jenkins Windows从机无视本地Git设置

4
我已经设置了一个Windows Jenkins从机到Unix Jenkins主机。我正在运行Windows 8.1,使用msysgit 1.9.5和Jenkins 1.616。
当检出路径/文件名超过255个字符的存储库时,我会收到“文件名太长”的错误。这可以通过在git设置中将core.longpaths设置为true来解决。然而,Windows Jenkins从机忽略自定义设置并使用标准设置。 我尝试过的方法
  • Setting core.longpaths on the Windows Jenkins slave in global, system, local settings:

    git config --global core.longpaths true
    git config --system core.longpaths true
    git config --local core.longpaths true
    
  • Setting core.longpaths on the Unix Jenkins Master

结果

Windows Jenkins从机仍然使用默认设置运行git。我已经创建了一个简单的构建任务。

"C:\Program Files (x86)\Git\bin\git.exe" config -l

产生

Started by user mles
[EnvInject] - Loading node environment variables.
Building remotely on jw10 in workspace D:\workspace\windowstesting
[windowstesting] $ sh -xe C:\WINDOWS\TEMP\hudson2817786906482449008.sh
+ 'C:\Program Files (x86)\Git\bin\git.exe' config -l
core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
Finished: SUCCESS

注意没有 core.longpaths=true。在Windows Jenkins从机上设置了 core.longpaths=true

C:\Users\jw>git config -l
core.symlinks=false
core.autocrlf=true
core.longpaths=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true

有效方法

在Windows Jenkins从机上不使用Jenkins本地克隆一个具有非常长的路径/文件名的存储库。

enter image description here

无法正常工作的内容

在Windows Jenkins从机上使用Jenkins克隆具有非常长路径/文件名的相同存储库时

    Started by user mles
    [EnvInject] - Loading node environment variables.
    Building remotely on jw10 in workspace D:\workspace\windowstesting
    Cloning the remote Git repository
    Cloning repository https://github.com/axelhodler/longfile.git
     > git init D:\workspace\windowstesting # timeout=10
    Fetching upstream changes from https://github.com/axelhodler/longfile.git
     > git --version # timeout=10
     > git -c core.askpass=true fetch --tags --progress https://github.com/axelhodler/longfile.git +refs/heads/*:refs/remotes/origin/*
     > git config remote.origin.url https://github.com/axelhodler/longfile.git # timeout=10
     > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
     > git config remote.origin.url https://github.com/axelhodler/longfile.git # timeout=10
    Fetching upstream changes from https://github.com/axelhodler/longfile.git
     > git -c core.askpass=true fetch --tags --progress https://github.com/axelhodler/longfile.git +refs/heads/*:refs/remotes/origin/*
     > git rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
     > git rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
    Checking out Revision 31b408748324aa6f361828e45ae1d374c3f0fc25 (refs/remotes/origin/master)
     > git config core.sparsecheckout # timeout=10
     > git checkout -f 31b408748324aa6f361828e45ae1d374c3f0fc25
    FATAL: Could not checkout null with start point 31b408748324aa6f361828e45ae1d374c3f0fc25
    hudson.plugins.git.GitException: Could not checkout null with start point 31b408748324aa6f361828e45ae1d374c3f0fc25
       ...
    Caused by: hudson.plugins.git.GitException: Command "git checkout -f 31b408748324aa6f361828e45ae1d374c3f0fc25" returned status code 128:
    stdout: 
    stderr: fatal: cannot create directory at 'launchpad/projects/configurationAdminManager/gofer-configurationAdminManager-notification/src/com/mwaysolutions/gofer2/configurationAdminManager/notification/dummydummy/dummydummy/dummydummy/dummydummy/dummydummy/dummydummy': Filename too long
       ....
    Finished: FAILURE

我不能在开始处添加另一个构建步骤来设置 core.longpaths,因为检出存储库是 Jenkins 在运行任何构建步骤之前执行的第一件事情。

有任何想法为什么我的 Windows Jenkins 从机会忽略自定义设置吗?

1
我怀疑Jenkins从机没有以用户“jw”身份运行。如果它是一个服务,它可能正在作为系统用户运行。您可以更改服务以作为专用用户“jw”运行。 - Eldad Assis
你的怀疑是正确的。将此作为常规答案添加,我会接受它。 - mles
3个回答

3

不要更改Jenkins从属的用户,您可以直接进行配置。

  • 建立一个名为JenkinsSlaveScripts的多配置项目,在适当的“管理员”视图下
  • 我使用基于矩阵的安全性来确保我的常规Jenkins用户不会运行它
  • 配置轴以在所有Windows从属上运行
  • 添加“执行Windows批处理脚本”任务

将脚本添加为(类似于)

cd c:\dev-software\git-2.7.1\bin
git config --global core.longpaths true
git config --system core.longpaths true
git config --local core.longpaths true
echo %USERPROFILE%\.gitconfig on %COMPUTERNAME%
type %USERPROFILE%\.gitconfig

当它运行时,无论谁作为从机运行,它都应该更新从机的配置。

这应该是答案,非常感谢您的回复!祝您点赞。 - Nick H.

2

Jenkins的从节点应该以用户jw运行。这将使git获取您为此用户设置的所有设置。
如果作为服务运行,请更新服务以以用户jw而不是系统用户运行。

希望这能帮到您。


0

在我的情况下有效的解决方案:

  1. 进入git安装文件夹,

  2. 然后编辑Git\etc\gitconfig文件,

  3. 确保它包含以下内容:

    [core] longpaths = true

例如:

[http]
    sslBackend = schannel
[diff "astextplain"]
    textconv = astextplain
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[core]
    autocrlf = false
    fscache = true
    symlinks = false
    longpaths = true
[pull]
    rebase = true 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接