kubernetes jenkins pipeline优化拉取大仓库性能指定分支+深度

有时候我们历史的git仓库,提交了某个比较大的文件如果不限制 depth ,就会拉取所有的历史提交记录,这样在历史仓库比较大的时候 clone 非常之慢,而实际上我们只需要最新的代码来构建就行了,为了优化性能,我们可以配置指定拉取:

关键配置:

复制代码
        stage('Check code') {
            echo("gitCommitId value is: ${gitCommitId}")
            // sh "sleep 10000"
            def scmVars = checkout([
                    $class: 'GitSCM',
                    branches: [[name: "${gitCommitId}"]],
                    extensions: [
                            [$class: 'CloneOption', depth: 1, shallow: true, noTags: true, honorRefspec: true, timeout: 3000]
                    ],
                    userRemoteConfigs: [[
                                                credentialsId: "${gitlabCredential}",
                                                url: "${gitlabURL}",
                                                refspec: "+refs/heads/${gitCommitId}:refs/remotes/origin/${gitCommitId}"
                                        ]]
            ])
            commitHash = scmVars.GIT_COMMIT.take(8)
            echo("${commitHash}")
        }

上面的拉取方式只适合拉取分支的,如果还要兼容commitId,需要下面的配置:

复制代码
// 判断是分支名还是 commit hash
def isCommitHash = gitCommitId ==~ /^[a-f0-9]{7,40}$/

def scmVars = checkout([
    $class: 'GitSCM',
    branches: [[name: isCommitHash ? "${gitCommitId}" : "origin/${gitCommitId}"]],
    extensions: [
        [$class: 'CloneOption', depth: 1, shallow: true, noTags: true, honorRefspec: true, timeout: 3000]
    ],
    userRemoteConfigs: [[
        credentialsId: "${gitlabCredential}",
        url: "${gitlabURL}",
        refspec: isCommitHash ? 
            "+${gitCommitId}:refs/remotes/origin/target-commit" : 
            "+refs/heads/${gitCommitId}:refs/remotes/origin/${gitCommitId}"
    ]]
])
相关推荐
YYYing.4 小时前
【K8s系列 (一) 】Docker与容器(上篇)
docker·云原生·容器·kubernetes
csdn_aspnet4 小时前
使用 Docker 和 RedisInsight 设置 Redis 以进行本地开发
redis·docker·容器·redisinsight
csdn_aspnet9 小时前
如何在本地 Docker 容器中运行 Redis,并使用 Redis Insight 和 Redis CLI 进行管理
redis·docker·容器
weirong10 小时前
给 Operator 加 Admission Webhook 踩的 4 个坑(其中 3 个本可以不踩)
kubernetes
Goboy12 小时前
夯爆了,我被一个一句话接入的免费可观测平台策反了,那一刻我决定放弃用了3年的Prometheus
后端·docker·kubernetes
吴声子夜歌12 小时前
Kubernetes权威指南——深入掌握Service(一)
云原生·容器·kubernetes
java_logo1 天前
Docker 部署 Liquibase:轻松搭建数据库变更管理
数据库·docker·容器·数据库管理·liquibase·轩辕镜像·数据库变更
IT利刃出鞘1 天前
Docker Compose--解决修改配置后不生效的问题
运维·docker·容器
java_logo1 天前
Docker 部署 CloudBeaver:轻松搭建网页数据库管理平台
数据库·docker·容器·数据库管理·dbeaver·轩辕镜像·cloudbeaver
好用斋1 天前
拾光坞安装网盘聚合LitePan:把Docker命令翻译成图形界面
运维·docker·容器