Select a quota list shared resource lock based on an expression

Hi Guys,

The solution you provided us here in Locking shared resources based on a combination of the selected agent and the job type?, this has been working successfully for us for a couple of years now! Thank so much for that!

I have a question about extending the logic, but before I ask it - let me recap / summarize our current solution described in this current thread:

We hold a server scoped shared resources quota list per each of our configuration types.
The labels in these quota lists are our actual agent hostnames, each with a quota of 1.
Our configurations have a condition to acquire a read lock:

  • Acquire any: read lock for ‘“Server.MyNameSpace.QuotaListForTypeAJobs”,“Quota list”’

And the (only) stage in our configurations has the following agent requirement:

$Build.SharedResources.Server.MyNameSpace.QuotaListForTypeAJobs.Labels.Any(Equals,$Agent.Hostname$)$

This achieves what we originally wanted:
Allow agents to run concurrent builds, but only 1 build of a specific type at the same time on the same agent.

My question is:
Can we somehow extend this logic to allow more than 1 agent pool (Quota list of agent hostnames) for a configuration? a default one, and others we can manually select before launching the configuration (based on a configuration variable value?)

If I understand correctly this is not possible because shared resource are acquired by selecting the shared resource to acquire from,
but perhaps if we use a complex acquire expression we can artificially “split” the labels in a quota list to artificial groups?

e.g.
acquire expression (pseudo code)
if %AgentPool%=A then acquire 1 label randomly from “Label_A, Label_B”;
if %AgentPool%=B then acquire 1 label randomly from “Label_C, Label_D”;

Do you think something like that could be possible or can you think of a different way to achieve this?

Thanks,
Arik

Hi Arik,

It’s not currently possible to use this sort of conditional logic when acquiring shared resource locks. The Acquire Expression operation can only be used to select a specific label based on an expression, but takes no account of whether that label is available. So even if you were able to specify your logic as an expression, it wouldn’t necessarily select the agent you want.

To achieve this, I imagine that you would need to be able to specify an expression or variable as the identifier of the shared resource. This variable or expression would expand to the name of a quota list shared resource based on the selected agent pool value. I’ll have a look into whether this is feasible, but I can’t promise anything.