I am using the Job DSL Jenkins plugin, and I have got a problem regarding the trigger. It is deprecated and when I update the code, then the deprecation warning is still shown.
Here the code before:
protected def job
void nightly(String schedule='H 0 * * *') {
job.triggers {
cron(schedule)
}
}
Then the update according to: https://github.com/jenkinsci/job-dsl-plugin/wiki/Migration
void nightly(String schedule='H 0 * * *') {
properties {
pipelineTriggers {
job.triggers {
cron(schedule)
}
}
}
}
There is still a warning: Warning: (JobBuilder.groovy, line 100) triggers is deprecated
What am I doing wrong? Is the properties keyword wrong or should it be job.properties?
thanks in advance
job
basically represents project
block of a job XML configuration file and its methods are converted to nested XML elements.
Your initial code
void nightly(String schedule = 'H 0 * * *') {
job.triggers {
cron(schedule)
}
}
renders this part:
<triggers>
<hudson.triggers.TimerTrigger>
<spec>H 4 * * *</spec>
</hudson.triggers.TimerTrigger>
</triggers>
Your updated code does effectively the same thing, because you are calling triggers
method of job
exactly like before the update. Another problem is that cron
method specification for pipelineTriggers
is different, so the correct code is:
void nightly(String schedule = 'H 0 * * *') {
job.properties {
pipelineTriggers {
triggers {
cron {
spec(schedule)
}
}
}
}
}
You can view available Jenkins DSL methods at https://your.jenkins.domain/plugin/job-dsl/api-viewer/index.html