Warm tip: This article is reproduced from stackoverflow.com, please click
git jenkins-pipeline

git clone without history using SCM

发布于 2020-03-27 10:14:56

Our project is huge and we would like to avoid cloning all git history.

Is it possible to git clone passing depth=1 using checkout scm in Jenkins?

I cannot find any documentation about how to configure SCM or how to pass arguments, if possible.

Added:
Found the documentation

https://jenkins.io/doc/pipeline/steps/workflow-scm-step/#code-checkout-code-general-scm

Type: int
depth (optional)
Set shallow clone depth, so that git will only download recent history of the project, saving time and disk space when you just want to access the latest version of a repository.

but it's not clear how to pass it to checkout scm

Questioner
marco
Viewed
255
Szymon Stepniak 2019-07-03 21:12

If you use scripted pipeline then you can customize checkout scm to look more or less like this:

node {
    checkout([
        $class: 'GitSCM',
        branches: scm.branches,
        doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
        extensions: scm.extensions,
        userRemoteConfigs: scm.userRemoteConfigs,
        depth: 1
    ])
}

If you use the declarative pipeline, then you need to go to your pipeline job configuration and in the Behaviors section you need to add Git -> Advanced clone behaviors and mark Shallow clone and set Shallow clone depth to 1.

enter image description here