We have a lot of jenkins tasks that process some date-dependent data,
for example, aggregations per hour, per day.
All of them are configured to run periodically
but native jenkins isn’t able to trigger periodical job automaticaly with dynamic parameters, and we have to calculate required parameters inside the script at
execution time,
e.g in the bash script code:
PREVHOUR=$(date --date="-1 hour" "+%Y-%m-%d %H")
We can also use $BUILD_ID environment variable to get build start time.
The problem is:
When all of the slots (workers) are busy, jenkins puts this job into
queue.
And the parameter calculations will be wrong when such a task is
executed next hour after triggering.
So, we can’t find the way to get TRIGGER time, not build starting time.
Of Course, there are few inconvenient solutions as:
- run simple periodical job on a reserved machine which triggers other jobs by url with params
- file that track the last run time of script
We have tried to find plug-ins that will fit our needs, and have found
this plugin, but it works only in manual (UI “build now” click) mode.
Is there any plug-in for Jenkins to calculate dinamic parameters at periodical trigger time?
Thanks!
You can use ScriptTrigger plugin. It evaluates Groovy script periodically and supports parameterized builds.
TRIGGER_TIMEparameter to a project.Use Groovy script:
It will write trigger time to a properties file “
trigger.time” on every polling and trigger a new build.Properties File Path(in advanced settings) to a “trigger.time“, and every scheduled build will getTRIGGER_TIMEparameter with designated time.