Search code examples
jenkinsconcurrencyjenkins-pipelinejenkins-plugins

Block Jenkins Builds execution if one with same parameters is already in progress


I know there is the throttle concurrent builds plugin that prevents two builds with the same parameters to run concurrently but even with that setup Jenkins still queues the second identical build that will eventually be executed.

I can't find a way or a plugin that allows me to block/discard/NotQueue the second job when another identical one is already running. There is this one but seems like its being deprecated.

Stumbled across this other question which might apply but I don't see the plugin available for Pipelines, just freestyle projects.

Any suggestions?


Solution

  • How are the builds being triggered? If there is a commit that is triggering them, you can ensure that the build doesn't get triggered for the same commit by marking the commit as "built" at the end of the pipeline. At the start of the pipeline, check to see if the build has been already built and if so, abort the build.

    If it gets triggered in some other way, your only option is to record which builds have gone through with which parameters, in something like a file or a database. Then, read this data source before the build is run.

    Edit: You could use a function such as this in the parent job to get the build parameters of the previous couple of jobs. Then, check if those params contain the same params in the build you are going to trigger. If so, don't trigger the build.