Sparse Checkout with Jenkins DSL Plugin?

会有一股神秘感。 提交于 2020-01-23 12:59:51

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!