I am using a Groovy script to get an email on a list of offline slaves from a Jenkins freestyle job. I have the following code under Jenkins freestyle Job > Build Environment > Evaluated Groovy script :
import hudson.model.Node
import hudson.model.Slave
import jenkins.model.Jenkins
String[] slaves = []
Jenkins jenkins = Jenkins.instance
for (Node node in jenkins.nodes) {
if (!node.toComputer().online) {
slaves += node.name
}
}
println "[OFFLINE SLAVES]: "+slaves
try{
emailext body: "${slaves}",
subject: "test subject",
to: "abc@xyz.com"
}
catch (Throwable t) {
println(t)
throw t;
}
The slave list is printing out fine but while calling emailext, the following ERROR is returned :
groovy.lang.MissingMethodException: No signature of method: Script1.emailext() is applicable for argument types: (java.util.LinkedHashMap) values: [[body:${slaves}, to:abc@xyz.com, subject:test subject]] 08:17:48 [EnvInject] - [ERROR] - Problems occurs on injecting env vars defined in the build wrapper: org.jenkinsci.lib.envinject.EnvInjectException: Failed to evaluate the script.
I am new to this and would appreciate some guidance on making this work. Thanks in advance.
Try like this:
try {
emailext (
subject: "test subject",
to: "abc@xyz.com",
body: "Offline Slaves : '${slaves}'"
)
}
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.