2
votes

I'd like to enable SCM polling in Jenkins by DSL code. As it's easily possible manually ( without DSL ) and works perfectly, but I'm looking for DSL code to Make it enable -- check attached image for reference.

I already checked below link, but no any solution here. https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.triggers.TriggerContext.scm

GitHub hook trigger for GITScm polling and Poll SCM

click here to check image

I'm not using Jenkins pipeline

3
Are you using jenkins pipeline ? - Fidel

3 Answers

1
votes

Finally I got solution for this:

Following are the DSL code to enable scm polling:

triggers {

   configure {
it / 'triggers' << 'com.cloudbees.jenkins.GitHubPushTrigger'{
    spec''
}
scm('')
            }
    }

I have tested, It's working perfectly

1
votes

Another Solution:

job('myjob') {
    configure { it / 'triggers' / 'com.cloudbees.jenkins.GitHubPushTrigger' / 'spec' }
}
0
votes

I had a similar situation when trying to enable scm polling for a pipeline.

I am configuring pipelines via job-dsl and CasC, and I specifically wanted to enable SCM polling.

So here's what I have working; I'm within the pipelineJob context, but I believe the solution is the same for the job context:

pipelineJob('myPipelineName') {
  environmentVariables {
    ...
  }
  definition {
    ...
  }
  configure { project ->
    project / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty' / 'triggers' / 'hudson.triggers.SCMTrigger' {
      'spec'('* * * * *')
    }
  }
}

The way I landed on this was manually changing a pipeline config (in the UI) to enable polling, then going and looking at the job's .xml on disk. The slash delimited stuff you see in the code above represents the xml tag path to the value i want to change.