我正在使用Jenkins Lockable Resources插件决定在我的声明性流水线中用于各种构建操作的服务器。我已经按照下表所示设置了我的Lockable资源:
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
我想锁定一个
label
,然后获取对应的锁定resource
的名称。
我编写了以下代码,但无法获得所需的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. */
}
< p > Lockable Resources Plugin
的文档在这里可用:https://jenkins.io/doc/pipeline/steps/lockable-resources/和https://plugins.jenkins.io/lockable-resources/
variable: 'var'
选项。 - Yash