Get groovy script output in Jenkins job console

9,956 views
Skip to first unread message

Maksym Grebenets

unread,
Jan 6, 2015, 10:37:35 PM1/6/15
to job-dsl...@googlegroups.com
Hi all

I'm trying to write a custom job DSL and currently face a problem with console output.
When I run the script on my development machine, all log statements (println) are showing up in console.
Works both in IDE (GGTS) and in shell session.

But when I run the same script as part of Jenkins seed job, none of the println messages are showing in job's console output.
I've seen some posts about so called bindings, but can't get them working.

This is how I call the script in Jenkins job
- clone the repository with script(s)
- run the script via Job DSL build step, in my case it's src/jobs/Seed.groovy
  I'm also specifying custom class path as 'src' so it picks up my other helper classes

So, how can I get log messages from groovy code showing up in Jenkins console output?
I need those for debugging right now.

Thanks.

Jan Hurst

unread,
Jan 7, 2015, 6:46:53 AM1/7/15
to job-dsl...@googlegroups.com
Are the messages coming from your custom classes? Or are the println statements in the Seed.groovy file?

I see the output of println statements in my equivalent Seed.groovy file but not the logback log messges from my custom classes that are imported into the .groovy file.

Maksym Grebenets

unread,
Jan 7, 2015, 7:26:58 AM1/7/15
to job-dsl...@googlegroups.com
messages are coming from custom classes

Maksym Grebenets

unread,
Jan 18, 2015, 7:36:33 PM1/18/15
to job-dsl...@googlegroups.com
Ok, I didn't realize there are things involved like bindings.
I found solution here
class Logger {

 
// Standard output
private static out = System.out

public static setOutput(out) {
this.out = out
}


public static log(String message) {
Logger.out.println(message)
}
}

def config = new HashMap()
def binding = getBinding()
config
.putAll(binding.getVariables())
Logger.setOutput(config['out'])


Now I can use 

Logger.log("message") from any class in my code.



Reply all
Reply to author
Forward
0 new messages