6

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

isherwood
  • 58,414
  • 16
  • 114
  • 157
marco
  • 1,686
  • 1
  • 25
  • 33
  • JFYI: if Jenkins has free executors on the node, it tries to re-use it instead of running the build on a random node. So most likely if you clone the repo once, it will be re-used next time. With time all your nodes (unless you clean them up) will have your Git repo and there won't be many full clones. – Stanislav Bashkyrtsev Jul 03 '19 at 12:57
  • Ok, but in case of `branch=develop`, we remove the entire build dir before cloning. – marco Jul 03 '19 at 13:00
  • I don't know why you would do this. Jenkins clears what needs to be cleared and there is no need to re-clone the repository. If you don't trust Jenkins - you can run `git reset --hard` and `git clean` on your own. This will be much faster than a shallow clone. – Stanislav Bashkyrtsev Jul 03 '19 at 13:13
  • Yea right and my fail, build dir has nothing to do with checkout dir – marco Jul 03 '19 at 13:15

1 Answers1

8

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

Szymon Stepniak
  • 40,216
  • 10
  • 104
  • 131