diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy index f7c842ae6..8cf0eebf6 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/ScmContext.groovy @@ -143,6 +143,7 @@ class ScmContext extends AbstractExtensibleContext { configVersion '2' disableSubmodules 'false' recursiveSubmodules gitContext.recursiveSubmodules + trackingSubmodules gitContext.trackingSubmodules doGenerateSubmoduleConfigurations 'false' authorOrCommitter 'false' clean gitContext.clean diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitContext.groovy index 3f345bc0f..26b63c9db 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/scm/GitContext.groovy @@ -22,6 +22,7 @@ class GitContext extends AbstractContext { boolean pruneBranches = false boolean ignoreNotifyCommit = false boolean recursiveSubmodules = false + boolean trackingSubmodules = false String localBranch String relativeTargetDir String reference = '' @@ -169,6 +170,14 @@ class GitContext extends AbstractContext { this.recursiveSubmodules = recursive } + /** + * Update tracking submodules to tip of branch. Defaults to {@code false} + * @since 1.40 + */ + void trackingSubmodules(boolean tracking = true) { + this.trackingSubmodules = tracking + } + /** * Prunes obsolete local branches. Defaults to {@code false}. */ diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslSampleSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslSampleSpec.groovy index b9394462a..79efda851 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslSampleSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/DslSampleSpec.groovy @@ -157,6 +157,7 @@ class DslSampleSpec extends Specification { 2 false false + false false false false @@ -300,6 +301,7 @@ mavenJob('PROJ-maven-with-template') { 2 false false + false false false false @@ -353,6 +355,7 @@ mavenJob('PROJ-maven-with-template') { 2 false false + false false false false diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy index a58936886..dff5ba5d9 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/ScmContextSpec.groovy @@ -1294,6 +1294,43 @@ class ScmContextSpec extends Specification { 1 * mockJobManagement.logPluginDeprecationWarning('git', '2.2.6') } + def 'call git scm with trackingSubmodules with default true'() { + when: + context.git { + remote { + url('https://github.com/jenkinsci/job-dsl-plugin.git') + } + trackingSubmodules() + } + + then: + with(context.scmNodes[0]) { + trackingSubmodules[0].value() == true + } + 1 * mockJobManagement.requirePlugin('git') + 1 * mockJobManagement.logPluginDeprecationWarning('git', '2.2.6') + } + + def 'call git scm with trackingSubmodules with param'(boolean value) { + when: + context.git { + remote { + url('https://github.com/jenkinsci/job-dsl-plugin.git') + } + trackingSubmodules(value) + } + + then: + with(context.scmNodes[0]) { + trackingSubmodules[0].value() == value + } + 1 * mockJobManagement.requirePlugin('git') + 1 * mockJobManagement.logPluginDeprecationWarning('git', '2.2.6') + + where: + value << [true, false] + } + def 'call git scm with recursiveSubmodules with param'(boolean value) { when: context.git {