This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jenkins-lib.git
The following commit(s) were added to refs/heads/master by this push:
new d6b592e Add option to allow non-shallow clones (#18)
d6b592e is described below
commit d6b592eb6e004d6f62cc907e869eca0dc9700fee
Author: Konrad Windszus <[email protected]>
AuthorDate: Tue Jun 16 20:05:50 2026 +0200
Add option to allow non-shallow clones (#18)
---
README.adoc | 8 +++
.../apache/maven/jenkins/GitCheckoutHelper.groovy | 66 ++++++++++++++++++++++
vars/asfMavenTlpPlgnBuild.groovy | 7 ++-
vars/asfMavenTlpStdBuild.groovy | 6 +-
4 files changed, 85 insertions(+), 2 deletions(-)
diff --git a/README.adoc b/README.adoc
index 70d3bad..acb465d 100644
--- a/README.adoc
+++ b/README.adoc
@@ -13,11 +13,15 @@ which can be referenced from Maven repo's `Jenkinsfile`:
- `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)
@@ -27,11 +31,15 @@ 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)
```
== Configuration in Jenkins
diff --git a/src/org/apache/maven/jenkins/GitCheckoutHelper.groovy
b/src/org/apache/maven/jenkins/GitCheckoutHelper.groovy
new file mode 100644
index 0000000..5bc6b39
--- /dev/null
+++ b/src/org/apache/maven/jenkins/GitCheckoutHelper.groovy
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.maven.jenkins
+
+class GitCheckoutHelper implements Serializable {
+
+ /**
+ * Performs a Git checkout with the specified configuration and fetch depth.
+ *
+ * @param script The Jenkins pipeline script context (usually 'this').
+ * @param scmConfig The SCM configuration for the Git checkout (set in the
Jenkins job configuration).
+ * @param fetchDepth The depth for shallow cloning (null for using the
default from scmConfig).
+ */
+ static void checkoutScm(def script, def scmConfig, def fetchDepth) {
+ if (fetchDepth == null || "${fetchDepth}".trim().isEmpty()) {
+ // simple checkout (with the job's scm configuration) if no explicit
fetch depth is specified
+ script.checkout(scmConfig)
+ return
+ }
+
+ // otherwise enrich default config to take into account the fetch depth
for a (non-)shallow clone
+ 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 = (scmConfig.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: true
+ ]
+ if (shallowClone) {
+ cloneOptions.depth = fetchDepthValue
+ }
+ extensions += [cloneOptions]
+
+ script.checkout([
+ $class: 'GitSCM',
+ branches: scmConfig.branches,
+ doGenerateSubmoduleConfigurations:
scmConfig.doGenerateSubmoduleConfigurations,
+ extensions: extensions,
+ submoduleCfg: scmConfig.submoduleCfg,
+ userRemoteConfigs: scmConfig.userRemoteConfigs
+ ])
+ }
+}
diff --git a/vars/asfMavenTlpPlgnBuild.groovy b/vars/asfMavenTlpPlgnBuild.groovy
index 80dda1e..909979a 100644
--- a/vars/asfMavenTlpPlgnBuild.groovy
+++ b/vars/asfMavenTlpPlgnBuild.groovy
@@ -19,6 +19,8 @@
* under the License.
*/
+import org.apache.maven.jenkins.GitCheckoutHelper
+
def call(Map params = [:]) {
Map taskContext = [:]
def branchesToNotify = params.containsKey("branchesToNotify") ?
params.branchesToNotify : ['master', 'main']
@@ -48,6 +50,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 +58,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 +187,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
+ GitCheckoutHelper.checkoutScm(this, scm, taskContext.fetchDepth)
if (isUnix()) {
sh 'df -hT'
sh cmd.join(' ')
@@ -223,3 +227,4 @@ def archiveDirs(archives, stageDir) {
}
}
}
+
diff --git a/vars/asfMavenTlpStdBuild.groovy b/vars/asfMavenTlpStdBuild.groovy
index c700017..aae2e00 100644
--- a/vars/asfMavenTlpStdBuild.groovy
+++ b/vars/asfMavenTlpStdBuild.groovy
@@ -19,6 +19,8 @@
* under the License.
*/
+import org.apache.maven.jenkins.GitCheckoutHelper
+
def call(Map params = [:]) {
def failingFast = null
def branchesToNotify = params.containsKey("branchesToNotify") ?
params.branchesToNotify : ['master', 'main']
@@ -42,6 +44,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 +105,7 @@ def call(Map params = [:]) {
pipelineGraphPublisher(disabled:
disablePublishers)
], publisherStrategy: 'EXPLICIT') {
dir ('m') {
- checkout scm
+ GitCheckoutHelper.checkoutScm(this, scm, fetchDepth)
if (isUnix()) {
sh cmd.join(' ')
} else {
@@ -176,3 +179,4 @@ def call(Map params = [:]) {
}
}
}
+