Jenkins launches time parameter settings

We have many jenkins tasks that process some data, depending on the date, for example, accumulations per hour, per day.

All of them are configured for periodic execution, but native Jenkins cannot automatically start automatic periodic work with dynamic parameters, and we must calculate the required parameters inside the script at runtime, for example, in the bash script code:

PREVHOUR=$(date --date="-1 hour" "+%Y-%m-%d %H") 

We can also use the $ BUILD_ID environment variable to get the build start time.

The problem is this: When all the slots (workers) are busy, Jenkins puts this work in line . And the calculation of the parameters will be incorrect if such a task is performed the next hour after launch.

Thus, we cannot find a way to get the TRIGGER time , and not build a start time.

Of course, there are several inconvenient solutions:

  • start simple periodic work on a reserved machine, which starts other tasks by URL with parameters
  • which tracks the last execution time of the script

We tried to find plugins that would suit our needs, and found this plugin , but it only works in manual mode (UI "build now" click).

Is there any plug-in for Jenkins to calculate dynamic parameters during periodic startup?

Thanks!

+4
source share
2 answers

You can use the ScriptTrigger plugin. It periodically evaluates the Groovy script and supports parameterized builds.

  • Add the TRIGGER_TIME parameter to the project.
  • Use Groovy script:

     now = new Date(); param = new File("trigger.time"); param.write("TRIGGER_TIME="+now.toString()); return true; 

    It will record the start time of the “ trigger.time ” properties file on each poll and start a new assembly.

  • Set Properties File Path (in additional settings) to " trigger.time ", and each scheduled assembly will receive the TRIGGER_TIME parameter with the assigned time.
+4
source

Two suggestions:

  • Starting a task, IMHO, is a perfectly reasonable decision. You can use a much more convenient way to get started, but a parameterized trigger plugin .

  • Another approach is to use the EnvInject Plugin . For example, you can calculate your parameters in a script, save them in a properties file and then insert environment variables from the file using the plugin. See this answer .

+2
source

Source: https://habr.com/ru/post/1412485/


All Articles