如何在Jenkinsfile中导入Groovy类?我试过几种方法,但都没有用。
这是我想导入的类:
Thing.groovy
class Thing {
void doStuff() { ... }
}这些事情是行不通的:
Jenkinsfile-1
node {
load "./Thing.groovy"
def thing = new Thing()
}Jenkinsfile-2
import Thing
node {
def thing = new Thing()
}Jenkinsfile-3
node {
evaluate(new File("./Thing.groovy"))
def thing = new Thing()
}发布于 2016-08-30 03:23:16
可以通过load命令返回类的一个新实例,并使用该对象调用"doStuff“
所以,你应该把这个写在"Thing.groovy“里
class Thing {
def doStuff() { return "HI" }
}
return new Thing();在dsl脚本中会有这样的内容:
node {
def thing = load 'Thing.groovy'
echo thing.doStuff()
}它应该将"HI“打印到控制台输出。
这能满足你的要求吗?
https://stackoverflow.com/questions/39208791
复制相似问题