I have a parameterized job which I want to schedule it to run at a particular time. Is there anyway I can choose my parameters and schedule it to run.
Thanks in advance
I have a parameterized job which I want to schedule it to run at a particular time. Is there anyway I can choose my parameters and schedule it to run.
Thanks in advance
At least two ways to handle this,
but you have to know the desired values in advance:
Set the job's default values to what you need,
then schedule it to run whenever you like.
Instead of scheduling the parameterized job,
create another job that will trigger the
parameterized job while passing the relevant
values to the parameters
(This also allows you to initiate the target-job
with different sets of values).
EDIT:
This third method will allow you to update the values of the parameters as needed:
Note it will be bad-practice to modify this file before each run,
as there are better ways to automatically initiate Jenkins-jobs with parameters.
EDIT 2:
A few years had passed, and now we have the Parameterized Scheduler
to help schedule a job at different times with different parameters
(see examples there for both "Classic" and Declarative Pipelines).
When build triggers are used to start a build, there's no way to pass parameters. Since the job is parameterized, the auto-start job will run with the default parameters.
If this is good enough , then you can simply set the schedule you want it to run via the 'Build Triggers' section of the job config page, you would then choose the 'Build periodically' checkbox and add the appropriate values (using syntax of cron). Let the default params take effect.
However, you could POST to jenkins as a trigger, and pass the exact values you wish. You then woudl have to use CRON directly for this with a shell script likely, so you can set the param values.
For example,
http://example.com/jenkins/job/this_job/buildWithParameters?PARAMETER=Value
Building on Gonen's answer a little bit, you can use the Build Flow Plugin to make this a bit easier on yourself. After installing, create a new job and set the type to "Build Flow". Configure this job to run at the desired, scheduled time. In the "Define build flow using flow DSL" section for this job, specify the job(s) you want it to build:
build( "Job You Want Built", param1:"whatever", Param2:"whatever")
You can specify more jobs to be built by adding more lines, or repeat the same line and change the parameters to build the job more than once with different params.
Once you're done, your Build Flow job will run at the scheduled time and kick off the desired jobs with the specified parameters.
The Jenkins crontab allows scheduling a job to run at a particular time but does not yet allow parameters to be passed.
However there is this Jenkins feature request to extend it to pass parameters. Once available it would let you do what you want without the need to create additional Jenkins jobs as some of the other answers suggest.
You can vote for this feature to be included in Jenkins sooner if it will help you.
You can use the Parameter Scheduler Plugin
It allows you to specify parameters after the cron schedule, for example:
H(0-29)/10 * * * * % name=value; othername=othervalue
The name value pairs after the % are interpreted as parameters.
It is possible to manually set values for parameters of parameterized job once and those values will be re-used in subsequent scheduled runs.
To do this, you need to define a default value for parameter like this:
parameters {
string(name: 'testUserName', defaultValue: params.testUserName ?: 'defaultTestUser')
}
See my detailed answer here
© 2022 - 2024 — McMap. All rights reserved.