带构建步骤的Jenkins GroovyShell

h9a6wy2h  于 2022-09-20  发布在  Jenkins
关注(0)|答案(1)|浏览(230)

我想执行作为我创建的.Jenkinsfile文件编写(和生成)的代码:

pipeline {
        stages {
            stage('validation') {
                steps{
                    script{
                        new GroovyShell().evaluate("""build (job:'myjob' , parameters:[string(name: 'FOO', value: "BAR")]""")
                    }
                }
            }
        }
    }

我收到错误:

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: Script1.string() is applicable for argument types: (java.util.LinkedHashMap) values: [[name:FOO, value:BAR]]
Possible solutions: toString(), toString(), print(java.lang.Object), print(java.io.PrintWriter), print(java.lang.Object), run()
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:71)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:80)

我不需要完全使用GroovyShell,执行字符串的任何变体都适合我

ctehm74n

ctehm74n1#

您可以将脚本移动到如下所示的文件中,然后使用load方法读取并执行它。

test.groovy

def call() {
    echo "Running the Job"
    build (job:'myjob' , parameters:[string(name: 'FOO', value: "BAR")])
}

return this;

管道

script{
    def exec = load "PATH/TO/SCRIPT/test.groovy"
    exec()
}

相关问题