Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jenkins 获取Groovy脚本名_Jenkins_Groovy_Jenkins Pipeline_Jenkins Groovy - Fatal编程技术网

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)
        }
    }