Reputation: 2414
Does anyone have a code sample for the correct
configure { ... }
block needed in the Jenkins DSL plugin to set up a git sparse checkout?
It appears as if the config.xml section looks like this:
<extensions>
<hudson.plugins.git.extensions.impl.CloneOption>
<shallow>false</shallow>
<reference>/build/jenkins/codebase.git</reference>
</hudson.plugins.git.extensions.impl.CloneOption>
<hudson.plugins.git.extensions.impl.SparseCheckoutPaths>
<sparseCheckoutPaths>
<hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<path>BillOfMaterials.yml</path>
</hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<hudson.plugins.git.extensions.impl.SparseCheckoutPath>
<path>jenkins/job/</path>
</hudson.plugins.git.extensions.impl.SparseCheckoutPath>
</sparseCheckoutPaths>
</hudson.plugins.git.extensions.impl.SparseCheckoutPaths>
</extensions>
Upvotes: 2
Views: 3551
Reputation: 1
This worked for me to create a folder with a shared library using DSL
folder("<your_folder_name_path>"){
properties {
folderLibraries {
libraries {
libraryConfiguration {
name("<your_shared_lib_name>")
implicit(true)
defaultVersion("<your_default_version>")
retriever {
scmSourceRetriever {
scm {
git {
credentialsId("<credentials>")
remote("<remote_url>")
traits {
cloneOptionTrait {
extension {
shallow( true )
noTags( true )
honorRefspec(true)
depth(1)
reference('')
timeout(10)
}
}
sparseCheckoutPathsTrait {
extension {
sparseCheckoutPaths {
sparseCheckoutPath {
path("<my_sparse_checkout_path>")
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Upvotes: 0
Reputation: 49
Current Jenkins / Job DSL versions allow producing multiple sparse checkout paths by specifying
git {
remote {
url('ssh://...')
credentials('...')
}
branch('*/master')
extensions {
sparseCheckoutPaths {
sparseCheckoutPaths {
sparseCheckoutPath {
path('path1')
}
sparseCheckoutPath {
path('path2')
}
}
Upvotes: 2
Reputation: 1145
Adding onto the answer given by 'nbsp' I had to add the following bold keywords(enclosed within double asterisk if bold not visible) to get it working. Hope this helps someone. :)
configure { git ->
git / 'extensions' / 'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' {
**sparseCheckoutPaths {**
sparseCheckoutPath.each { checkoutPath ->
'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {
path("${checkoutPath}")
}
}
**}**
}
}
Upvotes: 1
Reputation: 340
job('job1') {
description 'sparse checkout example'
scm {
git {
reference('/build/jenkins/codebase.git')
configure { git ->
git / 'extensions' / 'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' / 'sparseCheckoutPaths' {
['mypath1', 'mypath2', 'mypath3'].each { mypath ->
'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {
path("${mypath}")
}
}
}
}
}
}
}
Upvotes: 7