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

Jenkinsfile声明式流水线git插件如何设置shallow clone、depth及超时属性

修改后的完整配置

你可以直接在原有git方法中添加extensions字段配置浅克隆和超时参数,适配所有版本Jenkins Git插件的写法如下:

git(
    credentialsId: 'MY_GIT_CREDENTIALS', 
    branch: "${params.BRANCH}", 
    url: "${env.BBSCM}",
    extensions: [
        [$class: 'CloneOption', depth: 1, shallow: true, timeout: 1]
    ]
)

参数说明

  • depth: 1:配置浅克隆深度,仅拉取最近1次提交的代码,大幅缩减克隆耗时
  • shallow: true:显式开启浅克隆,兼容低版本Git插件,高版本插件仅配depth:1也可自动生效
  • timeout: 1:克隆操作超时时间,单位为分钟。当前Git插件暂不支持秒级超时配置,若你需要30秒超时,设置为1即可覆盖需求。

新版本插件简化写法

如果你使用的Jenkins Git插件版本≥4.0.0,可以用更简洁的cloneOptions写法,无需指定类名:

git(
    credentialsId: 'MY_GIT_CREDENTIALS', 
    branch: "${params.BRANCH}", 
    url: "${env.BBSCM}",
    cloneOptions: [depth: 1, shallow: true, timeout: 1]
)

内容的提问来源于stack exchange,提问作者Giuseppe Roberto Rossi

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 01:36:02