How to start and coordinate flow tasks in Jenkins - jenkins

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.

Related

Scheduling a parameterized build

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.

Upstream and downstream puzzle in Jenkins

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.

How to prevent jenkins from building a module while another one is building?

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.

How to trigger build with Continous Integration in TFS 2010 only if certain builds are not queued?

I'm struggling with the following issue.
Let's say we have solutions A, B, C and following dependencies:
A (no dependencies)
B -> A (B uses A)
C -> A,B (C uses A and B)
I've created builds with batched continous integration, so whenever I check in any of those solution, next builds are triggered.
Now, whenever I check-in A, B, C solutions, the build queue looks like that:
A
B
C
C (triggered after build B is Done)
B (triggered after build A is Done)
C (triggered after second build B is done)
but that takes too much time. Is there any way to make them trigger like that:
A
B (disregarded due to the fact that build A is in the queued and it's
not necessarily to build it)
C (disregarded due to the fact that build A is in the queued and it's
not necessarily to build it)
B (triggered from build A)
C (triggered from build B)
so that there are no duplicated builds in the queue. What about multiple user check-in's?
You can't do this out of the box. You would have to write an activity that checked that the other build was not running before doing a build.
Alternatively you seam to be in a bind. Why do you not publish each dependency as a Nuget package and take a dependency on that instead. Then you don't need a chained build.
You can do this by using a Rolling Build.
Team Foundation Server will collect any builds that are queued while a build is running and run them as one build. If that build fails, the build will be run separately to determine which build is the culprit.

Include a different job in a job's build steps in Jenkins

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.

Resources