6

I have a Jenkins job that uses MultiScm to clone 2 git repositories. During polling, I want it to ignore one of the 2 repos. I can set "Polling ignores commits in certain paths" manually in the configuration to make that work (using ".*" as path to exclude).

I want to enable this through job-dsl as the job is created trhough it; however, I can't find the config that has changed. The job's config.xml is identical with or without the "Polling ignores..." setting.

Any idea on how to enable this through job-dsl?

tarantoga
  • 1,096
  • 9
  • 19

1 Answers1

14

When I add the "Polling ignores commits in certain paths" behaviour, the following elements are added to the config XML:

<project>
  ...
  <scm class="org.jenkinsci.plugins.multiplescms.MultiSCM" plugin="multiple-scms@0.5">
    <scms>
      <hudson.plugins.git.GitSCM plugin="git@2.4.0">
        ...
        <extensions>
          <hudson.plugins.git.extensions.impl.PathRestriction>
            <includedRegions>foo</includedRegions>
            <excludedRegions>bar</excludedRegions>
          </hudson.plugins.git.extensions.impl.PathRestriction>
        </extensions>
      </hudson.plugins.git.GitSCM>
    </scms>
    ...
  </scm>
  ...
</project>

You can use the a Configure Block within the git context to add this config:

job('example') {
  multiscm {
    git {
      remote {
        github('jenkins/job-dsl-plugin')
      }
      configure { gitScm ->
        gitScm / 'extensions' << 'hudson.plugins.git.extensions.impl.PathRestriction' {
          includedRegions('foo')
          excludedRegions('bar')
        }        
      }
    }
  }
}
daspilker
  • 8,154
  • 1
  • 35
  • 49