You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jenkins中实现Git无Blob克隆?

Jenkins实现Git无Blob克隆的两种方案

插件原生实现(推荐)

Jenkins Git插件的cloneOption虽然没把filter做成单独配置项,但支持通过additionalArgs传递任意克隆参数,这属于插件原生支持的用法,不用自己写shell处理凭证:

checkout([
    $class: 'GitSCM',
    branches: [[name: '*/main']], // 替换成你要拉取的分支
    userRemoteConfigs: [[url: '你的Git仓库地址', credentialsId: '你的Jenkins凭证ID']],
    extensions: [
        [$class: 'CloneOption',
         additionalArgs: '--filter=blob:none',
         shallow: false] // 按需设置是否浅克隆,这里仅作示例
    ]
])

Shell脚本方式(备选)

如果原生插件的方式满足不了你的特殊需求,再用withCredentials绑定凭证后执行shell命令:

withCredentials([usernamePassword(credentialsId: '你的Jenkins凭证ID', usernameVariable: 'GIT_USER', passwordVariable: 'GIT_PASS')]) {
    sh """
        git clone --filter=blob:none https://${GIT_USER}:${GIT_PASS}@你的Git仓库地址.git
    """
}

这种方式自由度更高,但需要自己处理克隆目录、凭证清理等细节。


内容的提问来源于stack exchange,提问作者d4nyll

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 04:04:53