Dan M.
Dan M.

Reputation: 4052

Is there a way to emulate read-write lock for Jenkins Pipeline Jobs?

I have some unset number of jobs that use resource A in a "reading" manner. All these jobs can run concurrently just fine.

I've also have a job that "writes" to A. This job cannot run in parallel with "reader" jobs.

How would I solve this problem for Jenkins Pipelines? Is there a way to implement simple "read-write lock"? It looks like lock() can only be used to implement exclusive lock.

Upvotes: 4

Views: 835

Answers (1)

hakamairi
hakamairi

Reputation: 4678

There is a way, create multiple resources with label for example 'mylabel' (as many as many readers you have). I believe the quantity parameter is poorly documented.

Reader lock

lock(label: 'mylabel', quantity: 1) {
    ...

Writer lock - no quantity - so that's the default which is require all

lock(label: 'mylabel') {
    ...

Upvotes: 4

Related Questions