Queuing the entire Jenkins pipeline - jenkins

I have three jobs in my jenkins pipeline. The requirement is to queue the pipeline, ie, it should run as it is for the first build; for the second build (before the first gets completed), the flow should be - get all the 3 jobs done from the first build, then go for the second build.
PS: Is it possible through Build Blocker plugin? If so, how?

Related

Jenkins: distinguish CI build from scheduled build

All my Jenkins jobs are triggered both by a Github webhook, but also via a scheduled build one per week. The build process is heavily cached to make the webhook CI builds finish quickly.
I would like to add a line to my build script which wipes the cache during the weekly scheduled build, and make it build from scratch. Is there a variable in the build script to identify if a build was triggered by a webhook or schedule?
Maybe the envInject plugin will give you what you need?
This plugin also exposes the cause of the current build as an
environment variable. A build can be triggered by multiple causes at
the same time e.g. an SCM Change could have occurred at the same time
as a user triggers the build manually.
The build cause is exposed as a comma separated list:
BUILD_CAUSE=USERIDCAUSE, SCMTRIGGER, UPSTREAMTRIGGER, MANUALTRIGGER
In addition, each cause is exposed as a single envvariable too:
BUILD_CAUSE_USERIDCAUSE=true
BUILD_CAUSE_SCMTRIGGER=true
BUILD_CAUSE_UPSTREAMTRIGGER=true
BUILD_CAUSE_MANUALTRIGGER=true

How can the jenkins build can be discarded if no download stream is triggered?

There are two jobs in my jenkins server
job1 : build every 10 minutes to scan the events, if happens it triggers the downstream job2
job2 : normal job mostly run once in the case.
Problem:
too many useless jenkins build for job1 in the UI since it runs frequently.
It will be good if the build can be discarded if it doesn't trigger the downstream job.
Solution so far:, using Discard Old build plugin in post build action is one direction, but no clue how to get it works nicely.
With the hints from #JamesD's comments, I can use several plugins to achieve this
Archive artifacts Plugin: to archive the param.txt files which is used to path to downstream jobs
Groovy Postbuild job Plugin: add the groovy script to check whether the param.txt exists or not. The build will be set to Abort if it doesn't exists
Discard Old Builds Plugin: will discard the Abort build

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.

Run jenkins job without triggering downstream jobs

I have a jenkins job with a couple of downstream jobs which are triggered upon the job finishing correctly.
There are times when I want to run the initial job without triggering the downstream jobs. Is this possible?
It sounds like the conditional build step plugin might be of help. You can configure it to trigger other jobs based on various conditions, like so:
Here, the conditional build step has been configured to run downstream-job if foo.txt exists in the current workspace.

jenkins: promote before job ends

I'm trying to configure a job in jenkins in a way that the promotion process (Promoted builds plugin) happens in the middle of a run. The point is that there are some annoying tasks like javadocs, sonar integration,... that can be run even after the promotion process, therefore I would like to make the build, run all needed tests and then promote the build automatically. Other tasks can run after the promotion process.
Do you know how I can implement this using the Promoted builds plugin?
Thanks in advance for the help.
No, Promotions only run on completed builds. If you want to run it in the middle of the job, then it's a build step, not a promotion.
You can either configure build steps for your actions (same actions as promotions). You can even call other jobs, and wait for them to complete (or not wait).
Or you can configure your "after promotion" tasks as a second promotion that is executed after the first one.

Resources