How to write on Jenkins console output?
10,194
Valter, try this one. It's working in my scripts, I think it would also work in your scripts.
In groovy script, add this:
node("${config.slaveNodeName}") {
try {
stage ('CLONE') {
out.info(this,"SOME VERY USEFUL INFORMATION")
and change the class groovy script like this:
def info(script,msg){
LOGGER.info("${msg}")
script.echo "[INFO] ${msg}"
}
Related videos on Youtube
Author by
Valter Silva
Updated on June 04, 2022Comments
-
Valter Silva over 1 year
I'm coding a library for my Jenkins pipelines. I would like to print different formats for my messages, like
[INFO], [WARNING]
and so on.So far I have this:
import org.foo.Output def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() def out = new Output() node("${config.slaveNodeName}") { try { stage ('CLONE') { out.info("SOME VERY USEFUL INFORMATION") ...
And at my
org.foo.Output
class:package org.foo import java.util.logging.Logger class Output { private static final Logger LOGGER = Logger.getLogger(Output.class.getName()); def info(msg){ LOGGER.info("${msg}") echo "[INFO] ${msg}" <-- gives me an exception described below } }
I can see the
[INFO] SOME VERY USEFUL INFORMATION
on my Jenkins log, however, I would like to redirect this message to Jenkins output console.How can I do that?
Exception:
hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: org.foog.Output.echo() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [[INFO] SOME VERY USEFUL INFORMATION] Possible solutions: each(groovy.lang.Closure), info(java.lang.Object), wait(), grep(), any(), find() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:19)
-
jonrsharpe about 6 years
-
Valter Silva about 6 years@jonrsharpe Doesn't work, I have updated my question.
-
jonrsharpe about 6 yearsWithin the class it will look for a method; you could do e.g.
def out = new Output(echo)
to give the instance access to the step. -
Valter Silva about 6 years@jonrsharpe Sound a good idea! However, still not working
groovy.lang.MissingPropertyException: No such property: echo for class: standardGradleBuildPipeline
-