You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kw...@apache.org on 2026/06/08 15:57:20 UTC
(maven-jenkins-lib) branch feature/disable-shallow-clone created (now 79f319d)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch feature/disable-shallow-clone
in repository https://gitbox.apache.org/repos/asf/maven-jenkins-lib.git
at 79f319d Add option to allow non-shallow clones
This branch includes the following new commits:
new 79f319d Add option to allow non-shallow clones
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-jenkins-lib) 01/01: Add option to allow non-shallow clones
Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/disable-shallow-clone
in repository https://gitbox.apache.org/repos/asf/maven-jenkins-lib.git
commit 79f319d31f759084a6fb5b1e702e86350c7ed4e4
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Mon Jun 8 17:57:08 2026 +0200
Add option to allow non-shallow clones
---
README.adoc | 8 ++++++++
vars/asfMavenTlpPlgnBuild.groovy | 36 +++++++++++++++++++++++++++++++++++-
vars/asfMavenTlpStdBuild.groovy | 35 ++++++++++++++++++++++++++++++++++-
3 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/README.adoc b/README.adoc
index fc3723b..f16519a 100644
--- a/README.adoc
+++ b/README.adoc
@@ -11,11 +11,15 @@ This repository contains the Jenkins shared libraries that define the standard b
- `siteJdk`: array of jdks used for the site build (default: `[11']`)
- `siteMvn`: jdk used to build the site (default: `3.9.x`)
- `tmpWs`: boolean to shorten working directory on windows platform
+- `fetchDepth`: optional git fetch depth for checkout; values `> 0` enable shallow checkout with that depth, values `<= 0` force non-shallow checkout. When not set the organization value is used.
- `branchesToNotify`: array of branches to send notifications of the build (default: `['master', 'main']`)
Example to use a specific set of jdks and maven core
```
asfMavenTlpPlgnBuild(jdks:[ "8", "11" ], maven: ["3.8.x"])
+
+// checkout with explicit non-shallow clone
+asfMavenTlpPlgnBuild(fetchDepth: 0)
```
== asfMavenTlpStdBuild() (building Other projects)
@@ -25,9 +29,13 @@ asfMavenTlpPlgnBuild(jdks:[ "8", "11" ], maven: ["3.8.x"])
- `jdks`: array of jdks used for the build (default: `['8','11','17', '21']`)
- `maven`: maven versions used for build (default: `3.9.x`)
- `tmpWs`: boolean to shorten working directory on windows platform
+- `fetchDepth`: optional git fetch depth for checkout; values `> 0` enable shallow checkout with that depth, values `<= 0` force non-shallow checkout. When not set the organization value is used.
- `branchesToNotify`: array of branches to send notifications of the build and deploy artifacts (default: `['master', 'main']`)
Example to use a specific set of jdks and maven core
```
asfMavenTlpStdBuild(jdks:[ "8", "11" ], maven: "3.6.x")
+
+// checkout with explicit non-shallow clone
+asfMavenTlpStdBuild(fetchDepth: 0)
```
diff --git a/vars/asfMavenTlpPlgnBuild.groovy b/vars/asfMavenTlpPlgnBuild.groovy
index 80dda1e..00f1d8d 100644
--- a/vars/asfMavenTlpPlgnBuild.groovy
+++ b/vars/asfMavenTlpPlgnBuild.groovy
@@ -48,6 +48,7 @@ def call(Map params = [:]) {
def siteJdks = params.containsKey('siteJdk') ? params.siteJdk : ['11']
def siteMvn = params.containsKey('siteMvn') ? params.siteMvn : '3.9.x'
def tmpWs = params.containsKey('tmpWs') ? params.tmpWs : false
+ def fetchDepth = params.containsKey('fetchDepth') ? params.fetchDepth : null
taskContext['failFast'] = failFast;
@@ -55,6 +56,7 @@ def call(Map params = [:]) {
taskContext['archives'] = params.archives
taskContext['siteWithPackage'] = params.containsKey('siteWithPackage') ? params.siteWithPackage : false // workaround for MNG-7289
taskContext['shouldDeploy'] = shouldDeploy
+ taskContext['fetchDepth'] = fetchDepth
Map tasks = [failFast: failFast]
boolean first = true
@@ -183,7 +185,7 @@ def doCreateTask( os, jdk, maven, tasks, first, plan, taskContext )
"PATH+MAVEN=${ tool "$jdkName" }/bin:${tool "$mvnName"}/bin",
"MAVEN_OPTS=-Xms2g -Xmx4g -Djava.awt.headless=true"]) {
dir (stageDir) {
- checkout scm
+ checkoutScm(taskContext.fetchDepth)
if (isUnix()) {
sh 'df -hT'
sh cmd.join(' ')
@@ -223,3 +225,35 @@ def archiveDirs(archives, stageDir) {
}
}
}
+
+def checkoutScm(fetchDepth) {
+ if (fetchDepth == null || "${fetchDepth}".trim().isEmpty()) {
+ checkout scm
+ return
+ }
+ def fetchDepthValue = "${fetchDepth}".toInteger()
+ def shallowClone = fetchDepthValue > 0
+ // https://plugins.jenkins.io/git/#plugin-content-checkout-with-a-shallow-clone-to-reduce-data-traffic
+ def extensions = (scm.extensions ?: []).findAll { extension ->
+ def extensionType = extension instanceof Map ? extension['$class'] : extension?.getClass()?.name
+ extensionType != 'CloneOption' && extensionType != 'hudson.plugins.git.extensions.impl.CloneOption'
+ }
+ def cloneOptions = [
+ $class: 'CloneOption',
+ shallow: shallowClone,
+ noTags: false
+ ]
+ if (shallowClone) {
+ cloneOptions.depth = fetchDepthValue
+ }
+ extensions += [cloneOptions]
+
+ checkout([
+ $class: 'GitSCM',
+ branches: scm.branches,
+ doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
+ extensions: extensions,
+ submoduleCfg: scm.submoduleCfg,
+ userRemoteConfigs: scm.userRemoteConfigs
+ ])
+}
diff --git a/vars/asfMavenTlpStdBuild.groovy b/vars/asfMavenTlpStdBuild.groovy
index c700017..cf0bf78 100644
--- a/vars/asfMavenTlpStdBuild.groovy
+++ b/vars/asfMavenTlpStdBuild.groovy
@@ -42,6 +42,7 @@ def call(Map params = [:]) {
def maven = params.containsKey('maven') ? params.maven : '3.9.x'
def tmpWs = params.containsKey('tmpWs') ? params.tmpWs : false
def mavenArgs = params.containsKey('mavenArgs') ? params.mavenArgs : ''
+ def fetchDepth = params.containsKey('fetchDepth') ? params.fetchDepth : null
// def failFast = params.containsKey('failFast') ? params.failFast : true
// Just temporarily
def failFast = false;
@@ -102,7 +103,7 @@ def call(Map params = [:]) {
pipelineGraphPublisher(disabled: disablePublishers)
], publisherStrategy: 'EXPLICIT') {
dir ('m') {
- checkout scm
+ checkoutScm(fetchDepth)
if (isUnix()) {
sh cmd.join(' ')
} else {
@@ -176,3 +177,35 @@ def call(Map params = [:]) {
}
}
}
+
+def checkoutScm(fetchDepth) {
+ if (fetchDepth == null || "${fetchDepth}".trim().isEmpty()) {
+ checkout scm
+ return
+ }
+ def fetchDepthValue = "${fetchDepth}".toInteger()
+ def shallowClone = fetchDepthValue > 0
+ // https://plugins.jenkins.io/git/#plugin-content-checkout-with-a-shallow-clone-to-reduce-data-traffic
+ def extensions = (scm.extensions ?: []).findAll { extension ->
+ def extensionType = extension instanceof Map ? extension['$class'] : extension?.getClass()?.name
+ extensionType != 'CloneOption' && extensionType != 'hudson.plugins.git.extensions.impl.CloneOption'
+ }
+ def cloneOptions = [
+ $class: 'CloneOption',
+ shallow: shallowClone,
+ noTags: false
+ ]
+ if (shallowClone) {
+ cloneOptions.depth = fetchDepthValue
+ }
+ extensions += [cloneOptions]
+
+ checkout([
+ $class: 'GitSCM',
+ branches: scm.branches,
+ doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
+ extensions: extensions,
+ submoduleCfg: scm.submoduleCfg,
+ userRemoteConfigs: scm.userRemoteConfigs
+ ])
+}