Run multiple jenkins jobs in sequence with jenkins pipeline - jenkins

Gurus,
I have 4 jenkins jobs which I am triggering based on success and failure of previous job execution status.
Is there any way I can combine all the 4 jobs in a jenkins pipeline and have the same logic of checking if the previous execution successful or not?

Related

Triger to build pipeline job after successful another 5 jobs

How to trigger build pipeline job in Jenkins after some successful builds of another 5 jobs? I tried to use Build trigger but it work only for one successful build job, but not for all five of them.

Trouble stopping jenkins pipeline jobs

Trouble aborting pipeline jobs
We recently converted some of our jobs over to pipeline jobs (specifically, multibranch pipeline jobs), and since we did so, stopping builds has become much more problematic.
Back when they were freestyle jobs, the builds would immediately stop when we clicked the red X next to a build.
But when we do that in a pipeline job, often it won't stop. In the console output, we'll get something like this:
Aborted by [USERNAME]
Sending interrupt signal to process
Click here to forcibly terminate running steps
We have to click that link in the third line, and then it often leaves mercurial repositories in a bad state.
Why did stopping builds work fine with freestyle jobs, but not with Pipeline jobs, and is there any way to get them working well with Pipeline jobs?

Force Jenkins to run only one pipeline job and put rest all in queue

I would like to build only one project at a time in entire jenkins server. I have tried Jenkins throttle concurrent plugin and lockable resource plugin but no luck. As lockable resource plugin doesn't give me option to lock in pipeline job.
I have 3 Jenkins pipeline jobs (job have pipeline script):
JOB1
JOB2
JOB3
which has some common thing at beginning of the job (clearing content).
Running one by one manually doesn't have any problem if job completed but if JOB1 is building and JOB2 starts in between then it interrupts to JOB1 and build fails for JOB1.
Even when I start jobs using CLI, you never know which job might be running. So, I'm looking for solution to block JOBY if JOBX is running (X, Y can be 1,2 or 3) and allow only one job to run in entire Jenkins server. Like I said, throttle concurrent plugin gives customization option only for respective job instead of for multiple jobs?
Can anyone suggest some solution for multi pipeline jobs block to run only once?
Install Build Blocker Plugin
In configuration of JOBY check "Block build if certain jobs are running".
Put JOBX name in Blocking Jobs text area, each job on new line.
Note, you can also use regex to define in single line jobs having the same prefix but ending with different numbers.

Jenkins trigger a job only after one has completed and avoid parallel execution of jobs

I have two jobs in Jenkins: Job A that gets triggered on a commit and job B. Technically job B is triggered only after job A has been completed as job B is mentioned as a downstream of job A in the post build actions, but imagine this scenario:
Job A has been triggered by one commit and is running while the job B is still running from previous commit of job A, this is causing potential failures and complexity as both are running in parallel.
What is the best way to prevent both of them running in parallel?
These are the plugins I saw on jenkins wiki:
Build Blocker Plugin
Multijob Plugin
Still wanted to know the best course of action.
You can use the Multijob plugin for this and then both sub jobs will be wrapped in one job that is triggered by a commit.
You can avoid parallel execution of that job (in case of 2 commits in short time, the 1st commit will trigger the job, the 2nd will be 'pending')

How to prevent parallel execution of two downstream jobs triggered from two different upstream jobs

I have Job A which triggers two downstream jobs, say Job B and Job C. These two downstream jobs executes in parallel on master node. Job B then triggers another job say job 1 on a slave node and job C triggers job 2 on the same slave node almost at the same time. Number of executors configured on this slave node is 1 as i don't want job 1 and job 2 to run concurrently. Job 2 gets queued since job 1 is already running on that slave node. But when job 1 finishes execution, job 2 runs into executor starvation and gets stuck.
Issue:- Job 2 is running into executor starvation and gets stuck.
Is there any way in which once job 1 finishes execution, job 2 starts running instead of getting stack. i have also tried Throttle concurrent builds plugin but still the issue persists.
Thanks in advance!
There are several plugins that allow resource management:
https://wiki.jenkins-ci.org/display/JENKINS/Lockable+Resources+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Exclusion-Plugin
https://wiki.jenkins-ci.org/display/JENKINS/External+Resource+Dispatcher
Some block the job from executing, others have the job "wait" for the resource (while job is running).
You would have to setup your Job1 and Job2 to use some resource, so that they can wait for one another.

Resources