0
votes

In Jenkins you can set a job to build periodically using a cron-like time definition. e.g.

# switch timezone
TZ=Etc/GMT+6
# build once anywhere between 13:00 - 23:59
H H(13-23) * * *

Further you can configure parameterized jobs. That means on the go you can set the value of some predefined environment variables which will be used in the configuration. e.g. a certain branch on git you can let the user set the value of the environment variable "BRANCH" and than access this value using

${BRANCH}

in the configuration.


But this seems not to work with the Schedule value of a periodically build job configuration.

My problem:

I'm using the Job-Generator Plugin. It basically creates new (not parameterized but periodically running) jobs while using its own configuration as template.

In order to generate different jobs for different repositories you use the parameterized build as descriped before so in the generated job configuration the variable names ${...} are replaced by the value.

Now I don't want the Generator to run periodically but ofcourse only on demand. Therefor I want to replace the before mentioned cron rule by a variable so itself isn't build over night.

I tried to set CRON1 (TZ=Etc/GMT+6) and CRON2(H H(13-23) * * *) as unchngeable Generator variables and use

Schedule
    ${CRON1}
    ${CRON2}

but this makes Jenkins break and throw an error on trying to save the generator config.

line 1:1: unexpected char: '$'

How can I set the schedule value using an environment variable?

(I'm not trying to do Jenkins scheduled build Triggers with environment variable? . I'm using this but this doesn't solve my problem of the Job-Generator running periodically itself what it shouldn't)

1

1 Answers

-1
votes

You can't access the variables in that block, Instead you can use plugins to schedule the jobs. parameterized-scheduler-plugin this plugin can be helpful to you in your case. It does have good integration with pipeline scripting also. Hope this helps.