使用Jenkins做自动发布,每次发布会把项目组的资源git全部拉取下来,导致发布机上的.git太大,磁盘常常告警。
发布其实只需要最新的资源库内容,不需要拉取仓库的历史记录。
解决方案有两个:
- 清理文件和对应的提交索引记录——不推荐:风险大,而且历史记录可能有用
- 使用
git clone --depth
参数“浅”克隆——推荐使用
git clone --depth 1 -b master--single-branch https://xx/xx/resource.git
单一克隆master分支,只要该分支的最后1条记录,这样克隆,本地仓库会减少很多。
pipeline checkout语法:
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'CloneOption', depth: 1, noTags: false, reference: '', shallow: true]],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://xx/xx/resource.git']]
])
执行时转换成如下语句:
git fetch --tags --force --progress --depth=1 -- https://xx/xx/resource.git +refs/heads/*:refs/remotes/origin/* # timeout=10