Jenkins 获取Groovy脚本名
我有一个名为Jenkins 获取Groovy脚本名,jenkins,groovy,jenkins-pipeline,jenkins-groovy,Jenkins,Groovy,Jenkins Pipeline,Jenkins Groovy,我有一个名为a.groovy 在a.groovy中,我有: println(this.class.name) 当加载一个.groovy(运行它)时,我看到“Script1”是println的结果 如何获取加载的文件名—“a”或“a.groovy?” 更新1 我尝试了以下方法: class TrustedLib { void Test(Class scriptClass) { String scriptPath = scriptClass.pr
a.groovy
在a.groovy
中,我有:
println(this.class.name)
当加载一个.groovy
(运行它)时,我看到“Script1
”是println
的结果
如何获取加载的文件名—“a
”或“a.groovy
?”
更新1 我尝试了以下方法:
class TrustedLib {
void Test(Class scriptClass) {
String scriptPath =
scriptClass.protectionDomain.codeSource.location.path
println(scriptPath)
}
}
这是从脚本(节点
)调用的,如下所示:
Test
位于全局受信任库中,因为:
protectionDomain
scriptPath
显示为“/Groovy/shell
”(scriptClass
,顺便说一下是Script1
)
注:
如果我将测试更改为:
class TrustedLib {
void Test() {
String scriptPath =
getClass().protectionDomain.codeSource.location.path
println(scriptPath)
}
}
将打印路径/TrustedLib.groovy
,这是正确的路径
那么,再次失败-我如何获得真实的文件名?如何获得底层类?我很欣赏复制和粘贴的能力,但这与我的问题完全无关。你想实现什么?也许有一种不同的方法来模拟您的需求?我正在尝试根据脚本名称加载特定于脚本的/vars库。另一种方法是能够将参数传递给加载函数,因为这样可以将配置文件的名称作为参数传递给脚本。也就是说,是否有任何参数可以传递给
script.load
函数?
class TrustedLib {
void Test() {
String scriptPath =
getClass().protectionDomain.codeSource.location.path
println(scriptPath)
}
}