我正在尝试运行一个脚本来实例化扩展选择参数变量以在声明性 jenkinsfile 属性部分中使用它,但是我无法在没有步骤的情况下在 jenkinsfile 中运行脚本。我不想将其作为输入步骤或脚本管道。
所以我运行它首先是一个节点步骤,然后是一个管道步骤,如下所示:
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
node('MyServer') {
try {
def multiSelect = new ExtendedChoiceParameterDefinition(...)
properties([ parameters([ multiSelect ]) ])
}
catch(error){
echo "$error"
}
}
pipeline {
stages {
....
}
}
神奇地它起作用了!需要注意的是,只有当我之前只使用管道块运行过构建时。
那么,有没有更好的方法将以前的脚本运行到管道?能够在嵌入脚本块的步骤之外为属性或其他地方创建对象?