Reputation: 6627
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:
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!
Upvotes: 4
Views: 5965
Reputation: 56
You can use ScriptTrigger plugin. It evaluates Groovy script periodically and supports parameterized builds.
TRIGGER_TIME
parameter to a project.Use Groovy script:
now = new Date();
param = new File("trigger.time");
param.write("TRIGGER_TIME="+now.toString());
return true;
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 get TRIGGER_TIME
parameter with designated time. Upvotes: 4
Reputation: 16615
Two suggestions:
Trigger job, IMHO, is a perfectly reasonable solution. You may use a much more convenient method of triggering the jobs though - Parameterized Trigger Plugin.
Another approach is to use EnvInject Plugin. For example, you can calculate your parameters in a script, save them into a property file, and then inject the environment variables from the file with the plugin. See this answer.
Upvotes: 2