Plugin Information:
Plugins page: https://plugins.jenkins.io/block-same-builds
ID: block-same-builds
Latest Version: 1.3
Minimum Jenkins requirement: 1.625.3
Description: A plugin for Jenkins CI that blocks the running builds with the same configured parameters.
Screenshots:
Job configuration:
|
Standalone Jenkins job DSL Example
|
How it works
In the example, "CLIENT_ID" is the parameter set to check.
Build the job, with "CLIENT_ID": 12345, then rebuild the job with same "CLIENT_ID": 12345.
When the first job is running, the rebuild job will stop immediately and turn to gray. The build will totally stop.
Click into the build 11, we can see the reason why build stop: Reason: The job[jenkins-url] which has the same parameters triggered by user [username] is running!
Plugin Information:
plugins page: https://plugins.jenkins.io/throttle-concurrents
plugin GitHub page: https://github.com/jenkinsci/throttle-concurrent-builds-plugin/blob/master/README.md
ID: throttle-concurrents
Latest Version: 2.0.1
Minimum Jenkins requirement: 1.642.3
Description: This plugin allows for throttling the number of concurrent builds of a project running per node or globally.
The new feature we need to solve the problem: Prevent multiple jobs with identical parameters from running concurrently
This feature released version: 1.8.5
Current install version at https://lcjenkins.saas.bbpd.io/pluginManager/installed : 1.8.4
Screenshots:
Job configuration:
|
Standalone Jenkins job DSL Example
|
How it works:
In the example, "CLIENT_ID" is the parameter set to check.
Build the job, with "CLIENT_ID": 12345, then rebuild the job with same "CLIENT_ID": 12345.
When the first job is running, the rebuild job will become to the pending state and will show why this job is pending
However, after the first job finished, the rebuild job will RUN with the same parameter. This can prevent concurrent build with the same parameter on the one job, which can help to alleviate the pressure on servers
We can MANUALLY cancel this pending job based on this pending info, "A build with matching parameters is already running".
The positive aspect of this method, no matter we wait for the rebuild finish or cancel the pending job manually, there are no failed jobs or aborted jobs left on Build history panel, which can leave a clean build history for the operator.
After manually cancel the pending job, it will leave a clean build history
Steps:
We can list one Jenkins job all build status by curl the Jenkins API.
For example, list my local Jenkins one job all build from http://192.168.33.12:8080/job/Parameter-Category-Test1/api/json?tree=builds[building,id,number,result]&pretty=true
|
If the building is true and the result is null, means the build is running, we can list all running builds, and check their parameters, for example, "CLIEND_ID"