My Gerrit Server events are integrated to Jenkins (via Gerrit Trigger plugin) in such a way that 3 different Jenkins builds are triggered (say A,B,C) when Code Review +2 is received on a Gerrit PatchSet.
Currently any of the A, B or C builds are getting triggered first, there is no definite order. My requirement is to ensure that job A is triggered first, followed by B and C.
Is there any way to accomplish this?
Note: I can't setup a dependency job (say A->B->C) since I have many executors configured for this job. Setting a serial dependency would not utilise idle executors.
Add a quiet period to the B and C builds.
In Configuration > General > Advanced... > Quiet period
Related
I have a Jenkins server on K8s (using Rancher).
Job Y is configured to run after job X (image is attached).
Job X runs successfully, but at its end, job Y is not triggered.
Both jobs are on the same Jenkins master.
This problem has never happened to me before, on our Jenkins on prem servers.
I have checked everything I could think of, including creating test jobs that basically do nothing, just in order to test if the triggering is working for other jobs on this master, it does not.
Checking the logs - job x is in the log (image is also attached), job Y is missing from the log completely.
I will mention that on another master on the same cluster, triggering is working. Any ideas?
check the trigger condition for job Y.
Below is the one way you can trigger jobs in Jenkins
Chain jobs together
Chain Jenkins job together using the “Build other projects” option in the “Post Build Actions” of a job. The downside to this is that it introduces a dependency between jobs. For example, I want to be able to run the database backup job without doing a deployment every time.
Parameterized Trigger Plugin
When you have the Parameterized Trigger Plugin installed:
Create a wrapper job for your sequential jobs
For each sequential job
Select Build->Add build step->Trigger/call builds on other projects
Enter the sequential job name
Check the ‘Block until the triggered projects finish their builds’ checkbox (this only appears when you have the Parameterized Trigger Plugin installed)
Now when you run the wrapper job, all the triggered jobs will be run in order and sequentially. You of course also have the option of using the parameters functionality of the plugin too.
Throttle Concurrent Builds Plugin
The docs for the Throttle Concurrent Builds Plugin seem to be a little lacking, but it works well. With it installed, a “Throttle Concurrent Builds” section shows up in the Jenkins config section (Jenkins -> Manage Jenkins -> Configure System). There, you create a “Multi-Project Throttle Category”
Next, for each job that needs to be run sequentially, you
Check the ‘Throttle Concurrent Builds’ check box
Select the ‘Throttle this project as part of one or more categories’ radio button
Check the checkbox of the “Multi-Project Throttle Category” you created above
Save
Finally, you create a wrapper job that triggers all your to-be-run-sequentially jobs and when you run it, you should see your jobs running sequentially and in order.
Although a fairly complex option, this approach also allows you to run some jobs sequentially and others in parallel. For example, your wrapper job can run jobs A and B sequentially and jobs C and D sequentially, but trigger A and C in parallel. You can also combine this plugin with the Parameterized Trigger Plugin for maximum flexibility.
Join Plugin
Although I haven’t used the Join Plugin myself, it seems worth mentioning. Its docs state that
This plugin allows a job to be run after all the immediate downstream jobs have completed. In this way, the execution can branch out and perform many steps in parallel, and then run a final aggregation step just once after all the parallel work is finished.
That’s it. Several options for running Jenkins jobs in parallel. Choose the one that best suits your needs…
I have a set of components, one being the base component (A) and all others (B1 .. Bn) being dependent on the base component.
I have Jenkins jobs for each component which are triggered by SCM changes on the respective repositories. Now I would like to configure that a job of a Bx component waits if the base component A is currently building in order to have the latest build of A incorporated in its own build.
I looked at "throttle concurrent builds" plugin but I think I cannot use it in this case. Also I found code snippets to detect if another specific job is running. But then, how do I let the current job wait until the other is finished?
Try Build Blocker plugin, it does exactly what you need: you can specify job name of A component in Blocking jobs section for every job of Bx components.
Consider that I have jobs A,B,C,D in Jenkins.
Job A- contains my common code dependencies.
Job B,C,D- These are independent jobs, which refers to the dependencies in Job A.
Please note that A and B,C,D(have the upstream downstream relationship). I have added build triggers in each of them such that, each time a code is merged in GIT, it triggers the job.
The problem what I face is, Each time when the build is triggered for B, it invokes A. Now A has a list of downstream jobs C and D, it builds C and D jobs too. I want to make sure that, if B is triggered due to a commit then it should build only A and B jobs and not C and D.
I think there is a wrong configuration which i have set, kindly suggest.
I use jenkins version 1.643. Please let me know if there are plugins which can help me handle it.
I have the following build chain: A-->B
so when A is finished building the B building will start.
However, if the B build is in progress I don't want A to start a concurrent build until B is finished.
Is this possible?
You can use
https://wiki.jenkins.io/display/JENKINS/Build+Blocker+Plugin
to prevent job A from starting while job B is currently in progress, it will still be triggered but will wait in the queue till it completes.
However that plugin only works for freestlye jobs.
If the A and B are pipeline jobs you might want to create a shared resource and then lock it during the building of B
https://wiki.jenkins.io/display/JENKINS/Lockable+Resources+Plugin
You can limit the number of executors on the 'master' to just 1. It is not advisable as it may slow down the process. You can set it in Manage Jenkins > Configure System > # of executors. It will make sure that no concurrent builds are executed. But beware, that it will apply to all the builds.
Background of the problem
We are using jenkins to build lots of projects that are dependent to some of the projects.
As most of you know, jenkins allows you to trigger another job if the build is stable (stability is an option that we want). And there is another tool in jenkins that allows you to "block build if certain jobs are running". Also there is an option as "PrerequisitiesCheck".
Let say there is project A triggering project B and B is triggering project C. For the simplicity, let me say this configuration as A->B->C. Let say there is another path like A->X->C. First problem, if A and B are built successfully, C is triggered even Y is being built at the same moment. Solution is to use "block build if certain jobs are running" option. Second problem is, when A triggers B and X, and if B fails, then nevertheless X is triggering C and C fails because of B failed already. That is something that we do not want. Solution (not exact solution) is to use "PrerequisitiesCheck" option. At least with that option the person responsible for the project C can understand the problem did not occur due to project C. Also, we have to use trigger option to be able to link these A->B->C and A->X->C projects each other.
Problem
Problem is so simple, We do not want to use these three options (Trigger, PrerequisitiesCheck, Block build if certain jobs are running) because it is too much work and most probably this complex structure will cause many problems (i.e. forgetting linking is the simples one). Is there any tool that is doing three of them at the same time? Do you know any plugin enabling us to solve that problem wity only one linking?
Multijob plugin will be of interest to you.
This is what the documentation says.
After installing this plugin you will be able to do the following:
When creating new Jenkins job you have an option to create MultiJob project.
This job can define in the Build section phases that contains one job or more.
All jobs belong to one phase will be executed in parallel (if there are enough executors on the node)
All jobs in phase 2 will be executed only after jobs in phase 1 are completed etc.
Since A is triggering both B and X, I will make them run in parallel(making them part of same phase) and trigger C only when both are done.
Maybe the Build Flow Plugin is what you are looking for:
Build Flow Plugin
There you can write a little script which triggers your existing jobs, for example:
parallel (
// job 1, 2 and 3 will be scheduled in parallel.
{ build("job1") },
{ build("job2") },
{ build("job3") }
)
// job4 will be triggered after jobs 1, 2 and 3 complete
build("job4")