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.

Hi Arik,

We’ve uploaded a new version 1.9.2.1512 which includes features that you can use to achieve your requirements.

Shared resource lock expressions can now accept wildcards and lists of labels. We have also added some conditional logic functions to expressions.

After installing the new version follow these steps to allow selection of an agent pool as you described:

  1. Create the following “text” variables:

    %AgentPoolA% = “Agent1|Agent3”
    %AgentPoolB% = “Agent2|Agent4”

  2. Create a “numeric” variable named %SelectAgentPool% of type “Dropdown Select” or “Radiobutton Select” with these prompt options:

    “Agent Pool A” = 1
    “Agent Pool B” = 2

  3. Create a “expression” variable as follows using:

    %SelectedAgentPool% = “$Utils.SelectByIndex(%SelectAgentPool%, %AgentPoolA%, %AgentPoolB%)$”

    When evaluated, this expression will choose an agent pool based on the value of the %SelectAgentPool% selection.

  4. Create a shared resource lock for your quota list shared resource with the operation “Acquire Expression” and the label %SelectedAgentPool%. The lock will acquire an available label matching one in the selected agent pool in random order.

You should, of course, modify the variable values to suit your configuration. The agent requirement should remain the same as before.