在我的詹金斯工作中,我有一个选择参数,其中包含4个值(val1,val2,val3,val4)。
是否可以基于周期性时间事件动态设置选择参数值?
更确切地说,我想在每年的每个星期一动态更改此值。
例如:
Monday March 16 => it takes val1
Monday March 23 => it takes val2
Monday March 30 => it takes val3
Monday April 6 => it takes val4
Monday April 13 => it takes val1
依此类推。
所以,您的问题基本上可以归结为两个:
choice
参数中的默认值?考虑到您自己在#1的情况下表现不错(可能包括获取周数,然后将周数除以4),让我们解决第二个问题。
要根据某些Groovy脚本的结果来修改choices
参数,您可能希望在声明性脚本之前运行脚本化管道,如下所示:
def use_as_default = getValToUseAsDefault() // val1 on March 16, etc.
def list_of_vals = []
list_of_vals += use_as_default // first in the list will get to be selected
if (! ("val1" in list_of_vals) ) { list_of_vals += "val1"}
if (! ("val2" in list_of_vals) ) { list_of_vals += "val2"}
if (! ("val3" in list_of_vals) ) { list_of_vals += "val3"}
if (! ("val4" in list_of_vals) ) { list_of_vals += "val4"}
list_of_vals = Arrays.asList(list_of_vals)
pipeline
{
agent any
parameters
{
choice(name: 'VALS', choices: list_of_vals, description: 'Choose value')
}
...
}
def getValToUseAsDefault() {
// left as excersize to OP
return "val1"
}