Scope lock to folder

29 views
Skip to first unread message

John Lonergan

unread,
May 23, 2018, 5:42:16 AM5/23/18
to Jenkins Users
How do I scope locks so that on team's lock names don't accidentally collide with another's?

They seem to be created at server level rather than at folder level.

Any advice or patterns?
Right now I'm telling folk to be careful with naming.

More generally... from a resource management point of view it would seem that Jenkins would benefit from all "names" being scopeable to something narrower than global as this would reduce the admin burden and improve self service without increasing risk. Folder names are inherently scoped, and credentials can be created at folder scope, but what about node names and labels, or lock names or other such objects?

And then we can also talk about permissions. Who should be permitted to obtain a given lock and who not?

John Lonergan

unread,
Jun 3, 2018, 5:15:04 PM6/3/18
to Jenkins Users
Any info on scoped locks?
Server wide locks are a problem on a big instance as we get colliding names.

Brian Ray

unread,
Sep 17, 2018, 5:35:14 PM9/17/18
to Jenkins Users
In Pipeline we splice in the folder name to create lock resources for this reason. Note these are artificial, abstract resources created on the fly by the pipelines themselves just to have concurrency guards across pipelines in a folder. They don't correspond to any real concrete resource.

  //Chop the base job name, e.g. foo/bar/do-this > foo/bar.
 
final folder = JOB_NAME.replaceFirst( '/[^/]+$', '' )
 
lock( resource: "$folder::$stageName", inversePrecedence: true ) {
    stage
(stageName) {
     
...


I can't speak to lock permissions; we're not to that level of complexity yet.
Reply all
Reply to author
Forward
0 new messages