how to trigger the scheduled job which has parameters - jenkins

How to schedule the parameterized jenkins job?
I have a parameterized parent job which has 6 child jobs. when the parent job is triggered it should start the child jobs one after another.I should run the parent job for every 7 hours on weekend which I have given as H */7 * * 6-7.
My questions are:
How does the parent job takes the parameters when it is triggered?
Does it take the default choice or do i need a script to give the parameters?
How to configure if i want to skip any one of the child job?

Use the Parameterized Scheduler Plugin
1) Here's an example of passing parameters via the scheduler. If your job is parameterized, the plugin will add an option "Build periodically with parameters".
H */7 * * 6-7 % Environment=development; Version=2,4,3
2) I don't think it honors a default, I have not seen that in the docs. Let us know if you find something.
3) Via the parameters?

Related

How to handle a multivalue parameter in parametrised triggered Jenkins pipeline

We have a Jenkins pipeline which has a parameter called PIPELINE_ACTIONS, set by two checkboxes. The two checkbox options are:
FlashFirmware
RunTests
So it can run with PIPELINE_ACTIONS=FlashFirmware, PIPELINE_ACTIONS=RunTests and PIPELINE_ACTIONS=FlashFirmware,RunTests.
We are now trying to use Build Triggers to trigger the pipeline with specific parameters (Build periodically with parameters option in Jenkins). We would like to run it with PIPELINE_ACTIONS=FlashFirmware,RunTests but for some reason it does not work. Sounds like a formatting issue and I can't find any documentation on how to pass more than one value to a parameter with a cron string.
The current cron string looks like this:
# Runs every 2 minutes
H/2 * * * * % FW_VERSION=4.0C3;PIPELINE_ACTIONS=FlashFirmware,RunTests;
When we print PIPELINE_ACTIONS, it is empty. We tried with brackes, whitespaces, etc. but no combination worked.
How can it be achieved?
EDIT
Here is how the PIPELINE_ACTIONS parameter is defined:
For information, you can't use the default 'Build periodically' option to schedule a Jenkins job with parameters. You need to install the parameterized-scheduler plugin.
And With the Active Choices plugin, you might want to configure your parameter as follows:
You can of course use the scripted or declarative style (if you're using Jenkinsfile) to define your Active Choice parameter.
Finally schedule your build like the following:
H/2 * * * * %PIPELINE_ACTIONS=FlashFirmware,RunTests;FW_VERSION=1.0.0

How to Trigger back the Jenkins job from the job who triggered it?

Here, three different jobs triggers the JOB X. Requirement is, on completion of JOB X, it should trigger back the job who triggered it.
For example, if JOB X is triggered by JOB B, it should trigger back only the JOB B.
Things I have tried:
I have used "build another job" option from Post build action, where I can mention the list of jobs needs to be triggered.
It is not satisfying my requirement as it is triggering all the JOBS listed in the box.
Kindly help !!
You can use Parameterized Trigger Plugin :
Add a string parameter to your Job X, named ParentJob for example.
Use this parameter to configure the trigger of Job A, B or C : ${ParentJob}
Add a post build action "Trigger parameterized builds on other projects" on each of your other jobs (A, B and C).
Add "Predefined parameters" to this post build action and pass the name of the job in the parameter ParentJob : ParentJob=${JOB_NAME}

Jenkins pipelines is multiple parametrized cron build possible?

I have a working Jenkins scripted pipeline, very simple.
I am also using triggers to enable pipeline to run on a schedule.
Something like this:
node{
do_something()
triggers{
cron(‘* * * * *’)
}
}
do_something() does various things, and takes into account some input params (and env variables)
I want to trigger pipeline multiple times - lets say once a minute with some parameters, and every hour with other parameters.
(Imagine that I would like the same pipeline to be reused for continuous and full builds)
Is it possible?
I did not found a way how to do this, I am not even sure that it can be triggered by more than one trigger.
The trigger will trigger the entire job. It doesn't trigger parts of a job, or trigger with different parameters. What you probably want to do is setup a trigger job. Just have a simple pipeline job that triggers every minute, 10 minutes, whatever you need. That job will use logic in groovy to decide what needs to be done at that time and then trigger another job or jobs with the parameters you need.
Why don't you use the Parametrized Scheduler as trigger. This should do the trick for you:
triggers {
parameterizedCron('''
* * * * * %PARAM1=x;PARAM2=y
0 * * * * %PARAM3=z
''')
}

How to Pass Upstream Job Build Parameters to Downstream Jobs configured in a MultiJob Phase?

I have Upstream Job(MultiJob) which takes a String Parameter called freshORrerun, to take string value as "fresh" or "rerun" string value, which i need to pass on to downstream(standalone build) jobs to check the value is "fresh" or "rerun". Based on which, in child jobs's i will trigger complete tests run (pybot) or rerun (rebot) of failed tests.
here i have attached the screenshots how i have configured. When i print the passed string in child job it is empty.
Overall Job configuration.
Multi Job phase config and child Jobs
I have many no.of robot tests running them takes a lot of time. i need a way to run only failures of previous run, so that it gives me quick picture of how many got fixed. Could Some one please help me with this.
Click the 'Add parameters' button, select 'predefined parameters' and add: freshORrerun=${freshORrerun} to the list.
You can do it using one plugin called parameterized job trigger in which you will get options to pass parent job parameters to child job.
Note:- For this, you have to create parameters in child job also. These parameters will be overwritted.
plugin link

Trigger a child job after parent job has run multiple times in the day

I have a parent job which runs multiple times in a day, I have a child job which has to run only once a day only if the latest staus of parent job is successful.
Can you please let me know, different ways of doing it.s
Regards
Jagdish
Use Post build trigger
Trigger your child build if parent build is succeed.
Trigger one more child job from your child job to disable the job.
(you can easily disable or enable jobs by using groovy scipts.)
I would implement a simple counter + flag file.
Counter written to a file every time the parent job runs.
If the counter reaches N, create a flag file.
Use the Conditional BuildStep Plugin and check if flag file exists.
If exists, and parent build is good, reset counter, delete flag file and trigger child job.
I hope this helps.
Thnanks to you all for the ideas.I implimented this using a python script which compares current time with the time I want to run the job, if current time is less then it does not trigger the job and if it is equal to, greater than and less than one minute from runtime+1 min then it executes. So if my my designated runtime is 7PM, I compare current>7PM and current<7:01 PM.
So this way, even if parent job runs every 5 minutes, this child job triggers only once at 7PM. Use Trigger Remotely option to enable trigger remotely and execute this python script from parent job.

Resources