确定是否可以从其他groovy脚本调用groovy脚本

时间:2018-10-22 08:23:45

标签: jenkins-pipeline jenkins-groovy

我正在以自定义脚本的形式创建自定义的Jenkins管道步骤,该脚本动态生成需要调用的方法列表(其他管道步骤)。在这种情况下,我将从yaml文件中收集它们。

看起来像这样:

void call(Map args) {
    //gather tasks and their callable method from yaml

    tasks.each { task ->
        "$task.method"(task.parameters) //dynamically found method gets called here
    }
}

问题是。我不知道如何检查要调用的方法在运行时是否可用。

例如:

assert task.method == 'echo'
"$task.method"(task.parameters) //will work just fine, since `echo` is a standard pipeline step

assert task.method == 'httpRequest'
"$task.method"(task.parameters) //might fail if HTTP Request Plugin is not present at runtime

关于如何执行此可调用方法检查的任何想法,然后再开始一个接一个地调用它们,然后中途可能会出现异常?

0 个答案:

没有答案