jenkinsgroovyjenkins-pipelinejenkins-groovyjenkins-job-dsl

How can I find out if current Jenkins build is first run of the day from trigger


I have Jenkins jobs that trigger twice a day and I would like to know if the current build is the first cron trigger of the day or not and do some action.

My cron job is as below

 triggers {
    // regression --> 3:00GMT, 14:00GMT
    cron("00 3 * * 1-5 \n 00 14 * * 1-5")
}

Can I set some boolean param in my Jenkins file to check if it's the first trigger of the day?


Solution

  • Found the answer, it's simple but working fine for me. First I am checking if this is a scheduled job or not and the current hour is less than 5 (scheduled job runs before 5)

    def isItFirstScheduledJob = (params.JOB_IS_SCHEDULED && new Date().getHours() < 5) ? true : false