1

I have the below piece of code in groovy to schedule the job at 12 am IST.

I am using Job DSL plugin to seed the job.

Initial code-

triggers{
    cron{
     spec("TZ=Asia/Calcutta\n0 0 * * *")
    }
   }

For the same even though it works, I get depreciation warnings.

Warning: (jobName.groovy, line 18) triggers is deprecated

Second code-

void nightly(String schedule = 'H 0 * * *') {
  job.properties {
  pipelineTriggers {
  triggers{
    cron{
     spec("TZ=Asia/Calcutta\nH 0 * * *")
          }
        }
      }
    }
  }

The second one got failed with the below error message.

JobScriptsSpec > test script fr_oms_core_unit_perf_sanity_job.groovy FAILED
    org.spockframework.runtime.UnallowedExceptionThrownError at JobScriptsSpec.groovy:24
        Caused by: javaposse.jobdsl.dsl.DslException at JobScriptsSpec.groovy:21
            Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException at JobScriptsSpec.groovy:21

How can I avoid the same? Am I using the correct format?

Thanks in advance.

Varghese John
  • 91
  • 1
  • 7
  • Does this answer your question? [Jenkins Job DSL trigger is deprecated](https://stackoverflow.com/questions/62760438/jenkins-job-dsl-trigger-is-deprecated) – Noam Helmer Aug 02 '21 at 07:31
  • I have made substitutions in the code as in the question you have mentioned, but the seed job got failed due to the change. Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException at JobScriptsSpec.groovy:21 – Varghese John Aug 02 '21 at 07:57
  • @NoamHelmer Actually it didn't. I have edited the question above. – Varghese John Aug 02 '21 at 08:07

1 Answers1

3

The new syntax uses the pipelineTriggers directive under the properties directive instead of the deprecated triggers directive:

pipelineJob('MyPipelineJob') {
    properties {
        pipelineTriggers {
            triggers {
               cron{
                   spec("TZ=Asia/Calcutta\n0 0 * * *")
               }
            }
        }
    }
}

The documentation for the pipelineTriggers is available in your own Jenkins server in the following URL: https://your.jenkins.domain/plugin/job-dsl/api-viewer/index.html#path/javaposse.jobdsl.dsl.DslFactory.pipelineJob-properties-pipelineTriggers

Noam Helmer
  • 5,310
  • 1
  • 9
  • 29