I want to execute code which is written(and generated) as string I made.Jenkinsfile file:
pipeline {
stages {
stage('validation') {
steps{
script{
new GroovyShell().evaluate("""build (job:'myjob' , parameters:[string(name: 'FOO', value: "BAR")]""")
}
}
}
}
}
And I receive error:
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)
I do not need to use exactly GroovyShell, any variant of executing string will be appropriate for me
You can move your script to a file like below and then use the load
method the read and execute it.
test.groovy
def call() {
echo "Running the Job"
build (job:'myjob' , parameters:[string(name: 'FOO', value: "BAR")])
}
return this;
Pipeline
script{
def exec = load "PATH/TO/SCRIPT/test.groovy"
exec()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.