使用Jenkins DSL插件进行稀疏结账?

时间:2014-09-19 23:18:31

标签: jenkins jenkins-plugins jenkins-job-dsl

是否有人拥有正确

的代码示例
configure { ... }

在Jenkins DSL插件中需要阻止设置git稀疏结账吗?

看起来好像config.xml部分如下所示:

<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>

3 个答案:

答案 0 :(得分:7)

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}")
                        }
                    }
                }
            }
        }
    }
}

答案 1 :(得分:1)

添加'nbsp'给出的答案我必须添加以下粗体关键字(如果粗体不可见,则用双星号括起来)以使其正常工作。希望这有助于某人。 :)

configure { git ->
                git / 'extensions' / 'hudson.plugins.git.extensions.impl.SparseCheckoutPaths' {
                      **sparseCheckoutPaths {**
                            sparseCheckoutPath.each { checkoutPath ->
                               'hudson.plugins.git.extensions.impl.SparseCheckoutPath' {
                                    path("${checkoutPath}")
                                }
                            }
                      **}**
                }
           }

答案 2 :(得分:1)

当前的 Jenkins / Job DSL 版本允许通过指定生成多个稀疏结帐路径

        git {
          remote {
            url('ssh://...')
            credentials('...')
          }
          branch('*/master')
          extensions {
            sparseCheckoutPaths {
              sparseCheckoutPaths {
                sparseCheckoutPath {
                    path('path1')
                }
                sparseCheckoutPath {
                    path('path2')
                }
              }