How to schedule a build to run if it has been 3 days since another projects build was successful. For example,
Execute project A.
Wait 3 days.
Execute project B (parameterized project).
A build should not be triggered in this scenario -
Execute project A.
Wait 2 days.
DO NOT execute project B. Don't do anything.
Note - Project B is parameterized.
In order to execute a parameterized project, you need to:
Edit its Jenkinsfile to include the parameters; and
Execute the edited Jenkinsfile once so it would catch the schedule.
You can, in theory, save the schedule outside of Jenkinsfile, and build it from the scratch on executing the Jenkinsfile. In this case, you would need to:
Edit the schedule (that now resides outside of Jenkinsfile); but still
Execute the Jenkinsfile once so it would catch the schedule.
So, as you can see, there is a problem with your requirement.
In theory, you have the option of writing a new parameterized project (let's call it C) that will:
Wait 3 days.
Trigger project B to run at this time, with parameters of itself.
Your project A will then trigger (on the spot) the parameterized project C that will, in 3 days, trigger the parameterized project B.
Note that in case of Jenkins restart in these 3 days, your project B may run from the beginning, or not run at all.
Related
Project A executes continuously at around every minute
How can I also execute Project B every 2 hours?
At the time of Project B's execution Project A must be disabled / not executed.
That would depend on how you want things to run. If your Jenkins instance only have 1 slave with 1 job concurrency configured, you don't have to worry about build concurrency if there is two projects trying to build. One of them is gonna be picked and built, and then the another.
If i'm not wrong, Jenkins has 3 builders per slave for default, so probably the 2 projects would run at the same time. But you can always go on Configurations and tweak that.
pipeline {
options { lock resource: 'build-lock' }
stages {...}
}
use this in both of your pipelines. At any given point in time, either A or B will execute.
For more info Lockable resources
I've a Jenkins job I want to keep running all the time. When a build is ending, I want to immediately trigger another build. How can I do that?
Thanks, Omer
There are two different job configurations for that:
Build Triggers -> Build after other projects are built
Add a post-build action Build other projects
In both cases, you can enter your own Project, so it'll be triggered again every time a build is completed. You can also specify if this should be done only while the project is stable.
There is however one (probably more) drawback in this approach, which is that it'll create enormous overview pages, where all build triggers are listed:
So i'd recommend to do something else and for example use the Jenkins API to trigger a new build. There are many ways to do that, one simple example is adding a build step Execute shell and do something like:
curl -X POST http://localhost:8080/job/$JOB_NAME/build
If you have configured the Jenkins URL, you could also use $JOB_URL. You can also add post parameters to trigger a parameterized build.
I have a CI task in Jenkins that polls scm and builds my projects. Also there are several Autotests tasks:
Autotests project A
Autotests project B
Autotests project C
C depends on B which depends on A.
So, I want CI task to call Autotests A -> B -> C. But A task mustn't start again before C if finished. Suppose, during execution of A, B, C CI task was executed 3 times (as a result of 3 pushes to scm). In this case Autotests flow must be started only once for all three pushes.
How can I setup this with Jenkins? I use trigger plugin but it starts downstream tasks A, B, C each time (even previous Autotests flow hasn't finised), which is not desirable.
Under the project's advanced configuration are two options:
Block build when upstream project is building
Block build when downstream project is building
For project C, if you block its build while upstream projects are running, it won't run until A and B are done.
For project A, if you block its build while downstream projects are running, it will wait for B and C to finish before it runs.
Set the "Restrict where this job can be run" check box in your job A configuration and specify the name of your slave.
Then check the radio flag called 'Throttle concurrent builds' ( You will need https://wiki.jenkins-ci.org/display/JENKINS/Throttle+Concurrent+Builds+Plugin to do that ) And set overall and per node maximum builds to 1.
This will ensure that only one instance of job A will run at the given moment of time. The rest of the triggered jobs A will remain in queue and start only after the previous are completed.
I am trying to make this rather unique build flow and I haven't found a plugin or a way to do it with jenkins yet.
There is one job called "JOB A" which is used by itself and creates a standalone installer.
Then there is "JOB B" which creates another installer but it needs to include everything built in "JOB A" in addition to some other stuff. Now I could just copy JOB A build steps into JOB B, but I want to actually build JOB A and maybe even use those artifacts later as well.
It cannot be a build trigger cause JOB B needs to continue building after JOB A has finished and I cannot use something like flow because that creates JOB C and only sequences other jobs and I would need to go into A and B to get the artifacts.
Bonus points would be if it checked JOB A source code in git for any changes since its last build when building JOB B and decide if it needs to build it again.
I looked at many plugins and I can't seem to find one that would do this.
I hope my explanation was not confusing. Sorry if it was, I could elaborate.
If I understand correctly what you want, then what you need is:
Custom (shared) workspace
Parameterized Trigger Plugin
For both, JOB A and JOB B, setup Custom Workspace to the same folder on the server (You can even leave JOB A workspace as is, and just point JOB B custome workspace to workspace of JOB A. I am not at my work computer with Jenkins and can't provide screenshots, so I will borrow this great guide for more info on how to setup custom workspace
Then, whenever appropriate, have JOB A execute a build step Trigger/call builds on other projects, namely JOB B. You can even pass it all the same parameters that JOB A had. By default, this will not wait for JOB B to complete. It will kick off JOB B, meanwhile JOB A will finish running, and then JOB B completes whenever it is done.
If needed, you can check-mark Block until triggered projects finish their builds, and then JOB A will wait for JOB B to finish before continuing.
So, the above will:
Share workspace, and not do extra checkouts if code didn't change
Let JOB A and JOB B exist independently, with it's own artifacts, and each being able to be triggered separately.
JOB B will get everything from JOB A through shared workspace and passed parameters.
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")