Laucien
Laucien

Reputation: 521

Jenkins - How to handle concurrent jobs that use a limited resource pool?

I'm trying to improve some of the testing procedures at work and since I'm not an expert on Jenkins was hoping you guys could maybe point me in the right direction?. Our current situation is like this. We have a huge suite of E2E tests that run regularly. These tests rely on a pool of limited resources (AWS VMs that are use to run each tests). We have 2 test suites. A full blown regression that consumes, at its peak, a total of ~80% of those resources and a much more light weight smoke run that just uses 15% or so.

Right now I'm using the lockable resources plugin. When the Test Run step comes it checks whether you are running a regression or not and if you are then it will request the single lock. If it is available then all good and if not it will wait until it becomes available before continuing. This allows me to make sure that at no point there will be more than 1 regression running at the same point but it has a lot of gaps. Like a regression could be running and several smoke runs might be triggered which will exhaust the resource pool.

What I would like to accomplish on a best-case-scenario would be some sort of conditional rules that would decide whether the test execution step can go forward or not based on something like this:

Would something like that be possible from a Jenkins pipeline? In this case I'm using the declarative pipeline with a bunch of helper groovy code I've put together over time. My first idea is to see if there's a way to check if a lockable resource is available or not (but without actually requesting it yet) and then go through a bunch of if/then/else to set up the logic. But again I'm not sure if there's a way to check a lockable resource state or how many of a kind have already been requested.

Honestly, something this complex might probably be outside of what Jenkins is supposed to handle but I'm not sure and figured asking here would be a good start.

Thanks!.

Upvotes: 2

Views: 1581

Answers (2)

Laucien
Laucien

Reputation: 521

Completely forgot to update this but after reading and experimenting a bit more with the lockable resources plugin I found out you could have several resources under the same label and request a set quantity whenever a specific job starts.

I defined 5 resources and set the Jenkinsfile to check whether you are running the test suite with the parameter regression or not. If you are running a full regression it will try to request 4 locks while a smoke test will only try to request 1. This way when there aren't enough locks available the job will wait until either the enough amount becomes available or the timeout expires.

Here's a snippet from my Jenkinsfile:

        stage('Test') {
            steps {
                lock(resource: null, label: 'server-farm-tokens', quantity: getQuantityBySuiteType()) {
                  <<whatever I do to run my tests here>>
                }
            }

resource has to be null due to a bug in Jenkin's declarative pipeline. If you're using the scripted one you can ignore that parameter.

Upvotes: 2

user9105725
user9105725

Reputation:

Create a declarative pipeline with steps that build individual jobs. Don't allow people to run the jobs ad-hoc, or when changes are pushed to the repository, and force a build schedule.

How can this solve your issue:

Only 1 regression can be running at the same time.

Put all these jobs in sequence in a declarative pipeline.

If a regression is running allow only 1 smoke run to be run in parallel.

Put smoke tests that are related to the regression test in sequence, just after the regression build, but run the smoke tests in parallel, prior to the next regression build.

If no regression is running then allow up to 5 or 6 smoke tests.

See previous

If 2 or more smoke tests are running do not allow a regression to launch.

It will never happen if you run things in sequence.

Here is an ugly picture explaining what I am talking about. enter image description here

You can manually create the pipeline, or use the coolness of blue ocean to give you a graphical interface to put the steps in sequence or in parallel: https://jenkins.io/doc/tutorials/create-a-pipeline-in-blue-ocean/

The downside is that if one of those jobs fails, it will stop the build, but that is not necessarily a bad thing if the jobs are highly correlated.

Upvotes: 2

Related Questions