git sparse checkout within Jenkinsfile

I needed to checkout some code from another repository into my project, but I only wanted a specific directory within the other repository.

As usual with Jenkins, the docs are lacking, but reading the source for a bit I came up with the following:

dir('otherrepo') {
          checkout([$class: 'GitSCM',
            branches: [[name: '*/master']],
            doGenerateSubmoduleConfigurations: false,
            extensions: [
              [
                $class: 'SparseCheckoutPaths',
                sparseCheckoutPaths: [
                  [ $class: 'SparseCheckoutPath', path: 'goodthing/' ]]
                ]
              ],
            submoduleCfg: [],
            userRemoteConfigs: [[credentialsId: 'ACTIVE_DIRECTORY',
            url: 'https://github.com/uphillian/otherrepo.git']]
          ])
        }

According to the code, you should also be able to remove paths with `!` in the path, but I had trouble with this. I believe if the badpath is nested under the good path, it doesn't work.

dir('otherrepo') {
          checkout([$class: 'GitSCM',
            branches: [[name: '*/master']],
            doGenerateSubmoduleConfigurations: false,
            extensions: [
              [
                $class: 'SparseCheckoutPaths',
                sparseCheckoutPaths: [
                  [ $class: 'SparseCheckoutPath', path: '!goodthing/badthing/*', path: 'scripts/' ],
                ]
              ],
            submoduleCfg: [],
            userRemoteConfigs: [[credentialsId: 'ACTIVE_DIRECTORY',
            url: 'https://github.com/uphillian/otherrepo.git']]
          ])
        }

Doing this I only get the goodthing directory in the otherrepo directory in the workspace.

Wordpress category: 

Add new comment

Markdown

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.