Active Choice Reactive Parameters with Parameterized Scheduler - jenkins

I have some parameterized build in Jenkins with several Active Choice Reactive Parameters: par1, par2.
par1 is defined by combo, and par2 value depends on par1:
switch (par1) {
case 'value1': return 'test1'
case 'value2': return 'test2'
default: return 'test'
}
It works fine for manual trigger, but fails if I try to use parameterized shedule trigger:
H * * * * %par1=value1
Is it possible to solve this issue somehow?

Your input for periodic is supposed to run per hour (1).
Change this H * * * * %par1=value1 to either * * * * * every minute OR H/1 * * * * (1 hour) or H/2 * * * * (every 2 minutes). yea, it's kind of confusing when you use 1 it makes it one hour vs 1 minute (with H/1)
Also, make sure your par2 (Groovy code section within Active choice reactive parameter) is handling cases where par1 is not just a single value (test1) i.e. it can be test1,test2,test3,... when a user would have selected multiple values for par2 parameter (if it is a Multiple Select type).

Related

"H 5 * * 7" cron in Jenkins groovy script

I am trying to understand when this trigger runs in Jenkins groovy script. Seems to me that Jenkins groovy script has some DSL for cron. Does anyone know when this cron job is triggered?
triggers {
cron('H 5 * * 7')
}
In H 5 * * 7 the H means hash. You can have digit in the first place, but H allows to distribute the load better.
H = minute when less load is expected, Jenkins will propose it the first time, after that it will stay more or less the same, if there are available agents to handle it.
5 = hour,
* = any value (every day),
* = any value (every month),
7 = 7th day of week (Sunday).
Reference:
Spread load evenly by using ‘H * * * *’ rather than ‘5 * * * *’
You can test it using the CRONTab tester.
This means to start at 5:00 on every sunday
https://crontab.guru/#0_5_*_*_7

Jenkins: How to set a schedule for a parametrized job?

I want to set a schedule for a parametrized Jenkins job to start in different time with different parameters, but I can not find the correct syntax for this. I would like to have something like that:
30 1 * * * % VAR1=VALUE1, VAR2=VALUE2
30 2 * * * % VAR1=VALUE3, VAR2=VALUE4
How to do it correctly?
The answer is in the plugin README:
parameterized-scheduler-plugin README.md
# leave spaces where you want them around the parameters. They'll be trimmed.
# we let the build run with the default name
5 * * * * % furniture=chair;color=black
# now, let's override that default name and use Mr. Rubble.
10 * * * * % furniture=desk; color=yellow; name=barney
Not explicitly documented, but the example and the code show it to be PAIR_SEPARATOR= ";"
See also this "bug" - JENKINS-22129 and JENKINS--53220 and more

jenkins cron: run every 3rd minute, starting at 1

I want to set Jenkins to run a job every 3rd minute, but not starting at 0. Basically, I have 3 jobs and I want to cycle through them each minute.
The first job I can run every 3rd minute with */3 * * * *. But the second I tried 1/3 * * * * and it failed with hudson.remoting.ProxyException: line 1:2: unexpected token: /
How do I write this expression?
I think you're looking for:
job 1: 0-57/3 * * * *
job 2: 1-58/3 * * * *
job 3: 2-59/3 * * * *
Think of the cron minute entry as meaning "range/step" (or, "run this every step minutes over the minute range start-end)
Reference: I was able to figure it out from this excellent answer, which includes some helpful related links and a more in-depth explanation.

Jenkins exclude time(s) 2am-6am from Build Execution? - maybe use cron?

My Jenkins job executes Webdriver tests continuously however i need to exclude the hours of 2am between 6am, possible?
I know there are useful links available:
https://crontab.guru/#_5-23___
I added the following but dosnt seem to work:
* 6-23 * * *
* 1-2 * * *
* 0-1 * * *
If I understood well you need to exclude the hours from 2am to 6am (both included).
Something like this:
* 0-1,7-23 * * *
Implemented the following which I can confirm works:
* 0,1,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *

Spread load evenly by using ‘H * * * *’ rather than ‘5 * * * *’

When setting up how Jenkins shoul pull changes from subversion
I tried checked Poll SCM and set schedule to 5 * * * *, I get the following warning
Spread load evenly by using ‘H * * * *’ rather than ‘5 * * * *’
I'm not sure what H means in this context and why I should use that.
H stands for Hash
To allow periodically scheduled tasks to produce even load on the
system, the symbol H (for “hash”) should be used wherever possible.
For example, using 0 0 * * * for a dozen daily jobs will cause a large
spike at midnight. In contrast, using H H * * * would still execute
each job once a day, but not all at the same time, better using
limited resources.
Click on the question-mark beside your schedule specification.
It says there:
To allow periodically scheduled tasks to produce even load on the
system, the symbol H (for “hash”) should be used wherever possible.
For example, using 0 0 * * * for a dozen daily jobs will cause a large
spike at midnight. In contrast, using H H * * * would still execute
each job once a day, but not all at the same time, better using
limited resources.
Also in the documentation worth noting is that:
The H symbol can be used with a range. For example, H H(0-7) * * * means some time between 12:00 AM (midnight) to 7:59 AM. You can also use step intervals with H, with or without ranges.
The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project.

Resources