How to use trigger directive in a declarative pipeline?

1,205 views
Skip to first unread message

Idan Adar

unread,
Apr 7, 2017, 7:07:06 AM4/7/17
to Jenkins Users
It sounds obvious from reading the docs, but...

In a multi-branch pipeline there is no UI in Jenkins for defining a schedule to decide when should the job run automatically.
It seems that the following should do so, I don't understand how, given the file has to be read first after a checkout... but anyway...

I added the following triggers directive:

stages
    triggers
{
        cron
('H 4/* 0 0 1-5')
   
}


    stage
("...") {
   
...
   
}
}


But once running the job with this directive, it fails with the following:

java.lang.IllegalArgumentException: Could not instantiate {properties=[org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty@1523de8c, @pipelineTriggers(<anonymous>=[@cron(<anonymous>=0 12,16,20 0 0 0)])]} for JobPropertyStep
...
...

Idan Adar

unread,
Apr 7, 2017, 8:09:37 AM4/7/17
to Jenkins Users
FYI, The log is from my actual pipeline. The code snippet is just usage example.

Idan Adar

unread,
Apr 7, 2017, 10:00:21 AM4/7/17
to Jenkins Users
oops... disregard the snippet, it was wrong (but the failure is there anyway).

The following is the cron used.
I am attempting to run the job at 12:00, 16:00 and 20:00 on Sunday-Thursday... (every week, every month, every year).

triggers {
   cron '0 12,16,20 * * 1-4,7 *'
}

The error is the following. Why?

Caused by: antlr.ANTLRException: Invalid input: "0 12,16,20 * * 1-4,7 *": line 1:21: expecting EOF, found ' '

The documentation states that  "The Unix cron style syntax is supported."
I thus used the following as reference: http://www.nncron.ru/help/EN/working/cron-format.htm

Idan Adar

unread,
Apr 7, 2017, 10:07:06 AM4/7/17
to Jenkins Users
Okay, I tried various variations, this one works: 0 12,16,20 * * 1-4,7
Meaning: "At minute 0 past hour 12, 16, and 20 on every day-of-week from Monday through Thursday and Sunday."

Could someone now explain to me how this is supposed to work in Jenkins? How will Jenkins know when to actually run it _automatically_? i.e. schedule the job to run at the specified hours?

Mark Waite

unread,
Apr 7, 2017, 10:08:54 AM4/7/17
to Jenkins Users
That same exception is reported when you enter that cron specification into the "Poll SCM" field of a freestyle job.

I think the issue is that you have six fields in your cron specification, while the online help indicates it only accepts 5 fields.

I think you want 'H 12,16,20 * * 1-4,7' or if you really want it at the start of the hour rather than at some time during the hour, then '0 12,16,20 * * 1-4,7'.

Mark Waite

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3b6ffda4-1804-420f-9b14-6191ff85c578%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Idan Adar

unread,
Apr 7, 2017, 10:14:54 AM4/7/17
to Jenkins Users
Yep, thanks. In my last update I did the same cron as you.
Do you happen to know how does the triggers directive actually works with a declarative pipeline (Jenkinsfile)? how does it tell Jenkins to actually start the job at the specified hours?

Mark Waite

unread,
Apr 7, 2017, 10:18:19 AM4/7/17
to Jenkins Users

Idan Adar

unread,
Apr 7, 2017, 10:27:04 AM4/7/17
to Jenkins Users
Okay, I guess that after the first time the Jenkinsfile is read Jenkins must have saved this info somewhere as when looking at the job in Jenkins there is a "View Configuration" button and there you can see the specified schedule. sigh. I wish that'd be documented...

Mark Waite

unread,
Apr 7, 2017, 10:34:19 AM4/7/17
to Jenkins Users
I think the best thing you could do for the community is document it.  Find a reasonable place in the Jenkins Handbook, and submit a pull request with your information.  That will help others use what you've learned.

Mark Waite

On Fri, Apr 7, 2017 at 8:27 AM Idan Adar <id...@adar.me> wrote:
Okay, I guess that after the first time the Jenkinsfile is read Jenkins must have saved this info somewhere as when looking at the job in Jenkins there is a "View Configuration" button and there you can see the specified schedule. sigh. I wish that'd be documented...

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Idan Adar

unread,
Apr 7, 2017, 10:45:48 AM4/7/17
to Jenkins Users
The thought crossed my mind. Will do just that.
Reply all
Reply to author
Forward
0 new messages