Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-53991

cron job trigger for multibranchPipelineJob DSL

      Hi,

       

      I'm using multiBranchPipeline DSL to create a jobs like that:

      multibranchPipelineJob('${jobName}') {
          branchSources {
              git {
                  remote('${repo}')
                  credentialsId('${credentialsId}')
                  includes('${branches}')
              }
          }
          orphanedItemStrategy {
              discardOldItems {
                  numToKeep(20)
              }
          }
          configure {
              it / factory(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory') {
                  owner(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject', reference: '../..')
                  scriptPath('${jenkinsfilePath}')
              }
          }
      }

      Everything works fine, but now I want to trigger job automatically by cron.

      According to docs I can use https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob-triggers-cron

      But it doesnt work for me.  I'm adding this to DSL snippet:

      triggers {    cron('@daily')}

      But Build Triggers section for the job is completely virgin.

      Am I missing something there? How can I debug this problem?

       

      UPDATE
      In job's config.xml I found this section:

      <triggers>
          <hudson.triggers.TimerTrigger>
              <spec>@daily</spec>
          </hudson.triggers.TimerTrigger>
      </triggers>

          [JENKINS-53991] cron job trigger for multibranchPipelineJob DSL

          Stanislav Pugachov created issue -
          Stanislav Pugachov made changes -
          Description Original: Hi,

           

          I'm using multiBranchPipeline DSL to create a jobs like that:
          {noformat}
          multibranchPipelineJob('${jobName}') {
              branchSources {
                  git {
                      remote('${repo}')
                      credentialsId('${credentialsId}')
                      includes('${branches}')
                  }
              }
              orphanedItemStrategy {
                  discardOldItems {
                      numToKeep(20)
                  }
              }
              configure {
                  it / factory(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory') {
                      owner(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject', reference: '../..')
                      scriptPath('${jenkinsfilePath}')
                  }
              }
          }{noformat}
          Everything works fine, but now I want to trigger job automatically by cron.

          According to docs I can use [https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob-triggers-cron]

          But it doesnt work for me.  I'm adding this to DSL snippet:
          {noformat}
          triggers { cron('@daily')}{noformat}
          But Build Triggers section for the job is completely virgin.

          Am I missing something there? How can I debug this problem?

           
          New: Hi,

           

          I'm using multiBranchPipeline DSL to create a jobs like that:
          {noformat}
          multibranchPipelineJob('${jobName}') {
              branchSources {
                  git {
                      remote('${repo}')
                      credentialsId('${credentialsId}')
                      includes('${branches}')
                  }
              }
              orphanedItemStrategy {
                  discardOldItems {
                      numToKeep(20)
                  }
              }
              configure {
                  it / factory(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory') {
                      owner(class: 'org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject', reference: '../..')
                      scriptPath('${jenkinsfilePath}')
                  }
              }
          }{noformat}
          Everything works fine, but now I want to trigger job automatically by cron.

          According to docs I can use [https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob-triggers-cron]

          But it doesnt work for me.  I'm adding this to DSL snippet:
          {noformat}
          triggers { cron('@daily')}{noformat}
          But Build Triggers section for the job is completely virgin.

          Am I missing something there? How can I debug this problem?

           

          UPDATE
          In job's config.xml I found this section:
          {noformat}
          <triggers>
              <hudson.triggers.TimerTrigger>
                  <spec>@daily</spec>
              </hudson.triggers.TimerTrigger>
          </triggers>{noformat}
          Stanislav Pugachov made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Gavin Mogan made changes -
          Component/s New: job-dsl-plugin [ 16720 ]

            Unassigned Unassigned
            spugachev Stanislav Pugachov
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: