Varghese John
Varghese John

Reputation: 101

Jenkins triggers gets depreciated

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.

Upvotes: 2

Views: 1236

Answers (1)

Noam Helmer
Noam Helmer

Reputation: 6824

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

Upvotes: 3

Related Questions