问题
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>
回答1:
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}")
}
}
}
}
}
}
}
回答2:
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}")
}
}
**}**
}
}
来源:https://stackoverflow.com/questions/25943651/sparse-checkout-with-jenkins-dsl-plugin