can I run a stage at a certain time within a pipeline

30 views
Skip to first unread message

jesus fernandez

unread,
Sep 26, 2020, 5:55:14 AM9/26/20
to Jenkins Users
I have a declarative pipeline with 3 stages and it is using poll SCM every 10 minutes (checkout, build and deploy), but I need the last step (deploy) to be executed just once everyday (i.e. 22 o´clock)  so it keeps checking out and building everytime a change is submitted but it only deploys once a day. I have tried to use triggers cron directive within the stage but it does not work. I have thought to use the when directive but as I am new to groove I do not see how to tell jenkins "when time is 22 o´clock"

Thanks

Victor Martinez

unread,
Oct 30, 2020, 2:48:15 PM10/30/20
to Jenkins Users
triggeredBy within the stage context should help you: https://www.jenkins.io/doc/book/pipeline/syntax/#when

pipeline {
   ...
   triggers {
     cron 'H H22 * * 1-5'
   }
   stages {
        ...
        stage('deploy') {
           when { triggeredBy 'TimerTrigger' }
           ...

jesus fernandez

unread,
Nov 6, 2020, 6:19:41 AM11/6/20
to Jenkins Users
Gracias Victor!
Reply all
Reply to author
Forward
0 new messages