I am using Jenkins Lockable Resources plugin to decide which server to be used for various build operations in my declarative pipeline. I have set up my Lockable Resources as shown in the table below:
Resource Name Labels
Win_Res_1 Windows
Win_Res_2 Windows
Win_Res_3 Windows
Lx_Res_1 Linux
Lx_Res_2 Linux
Lx_Res_3 Linux
I want to lock a label
and then get the name of the corresponding locked resource
.
I'm writing following code but am not able to get the desired value of r
int num_resources = 1;
def label = "Windows"; /* I have hardcoded it here for simplicity. In actual code, I will get ${lable} from my code and its value can be either Windows or Linux. */
lock(label: "${label}", quantity: num_resources)
{
def r = org.jenkins.plugins.lockableresources.LockableResourcesManager; /* I know this is incomplete but unable to get correct function call */
println (" Locked resource r is : ${r} \n");
/* r should be name of resource for example Win_Res_1. */
}
The documentation for Lockable Resources Plugin
is available here: https://jenkins.io/doc/pipeline/steps/lockable-resources/
and
https://plugins.jenkins.io/lockable-resources/