Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Jenkins Job DSL to set "Polling ignores commits in certain paths" for Git plugin

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?

like image 948
tarantoga Avatar asked Nov 18 '15 23:11

tarantoga


People also ask

What is DSL plugin in Jenkins?

The Job DSL plugin provides a solution, and allows you to configure Jenkins jobs as code. In this tutorial, you'll use Job DSL to configure two demo jobs: one that prints a 'Hello World' message in the console, and one that runs a pipeline from a Git repository.

When can we use GitHub plugin in Jenkins?

Can You Use Jenkins With GitHub? You can and should use Jenkins with GitHub to save time and keep your project up-to-date. One of the basic steps of implementing CI/CD is integrating your SCM (Source Control Management) tool with your CI tool. This saves you time and keeps your project updated all the time.

Which plugin allows use of Git as a SCM?

Rundeck provides SCM Export and SCM Import providers for Git. This plugin allows Source Code Management of the jobs, versioning, exporting or importing their definitions using a remote Git repository.


1 Answers

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="[email protected]">
    <scms>
      <hudson.plugins.git.GitSCM plugin="[email protected]">
        ...
        <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')
        }        
      }
    }
  }
}
like image 141
daspilker Avatar answered Oct 14 '22 01:10

daspilker