Need help on usage of Jenkins console data

150 views
Skip to first unread message

AJITH K.R

unread,
Jun 14, 2016, 6:34:47 AM6/14/16
to Jenkins Users
Hi All,

How can I get the console output information of Jenkins build under the workspace. I need to use it as an input for reporting purpose. 

Thanks,
Ajith

Ginga, Dick

unread,
Jun 14, 2016, 8:16:45 AM6/14/16
to jenkins...@googlegroups.com

Ajith, I’m sure you can use a Post-build “Groovy Post-Build” to read the log (build.getLog maybe) and the write it to a file in the workspace. There might be a easier way and this code has not been “tested”.

 

Try something like this:

 

Log = build.getLog();

 

// is we are running on a remote slave, we need the channel

 

if (manager.build.workspace.isRemote()) {

   channel = manager.build.workspace.channel;

}

 

// create a FilePath object to use to write into the remote workspace

 

fp = new hudson.FilePath(channel, build.workspace.toString() + "\\log.filename")

 

if (fp != null) {

      fp.write(Log, null);

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f0b1f482-6979-44ee-9b17-52c39ad33928%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maciej Jaros

unread,
Jun 14, 2016, 1:06:06 PM6/14/16
to jenkins...@googlegroups.com
Another method (without using Groovy) is to simply get path and do whatever you need with it.
buildLogPath="../builds/$BUILD_NUMBER/log"

Might be a good idea to copy the file if you are going to change it or you need to make sure it's not change during other operations.
buildLogPath="../builds/$BUILD_NUMBER/log"
cat $buildLogPath > ./build.log.copy
# run reports asynchronously
doreportrs ./build.log.copy &

Regards,
Nux.

AJITH K.R

unread,
Jun 15, 2016, 5:55:41 AM6/15/16
to Jenkins Users, mac...@mol.com.pl
Thanks Nux for the suggestion. I have few more concerns. I use an enterprise version of Jenkins and I run the project in a linux slave. Is there any way i can get the path of the log. Using some $ commands as such. Please help me with this.

Thanks,
Ajith

AJITH K.R

unread,
Jun 15, 2016, 6:17:05 AM6/15/16
to Jenkins Users
Thanks for the suggestion. I am completely new to groovy and I tried executing the script in post groovy step but it failed in step build.getLog() :-(.

Ginga, Dick

unread,
Jun 15, 2016, 7:26:47 AM6/15/16
to jenkins...@googlegroups.com

And the error was??

AJITH K.R

unread,
Jun 15, 2016, 11:27:28 AM6/15/16
to Jenkins Users
Below is the error. I am just listing my directory in the shell. In post build section creating a groovy script.
+ ls -lrt
total 0
-rw-r--r-- 1 jenkins jenkins 0 Jun 15 06:25 build.log.copy
ERROR: Failed to evaluate groovy script.
groovy.lang.MissingPropertyException: No such property: build for class: Script1
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
	at Script1.run(Script1.groovy:1)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)
	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript.evaluate(SecureGroovyScript.java:168)
	at org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:362)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:720)
	at hudson.model.Build$BuildExecution.post2(Build.java:185)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:665)
	at hudson.model.Run.execute(Run.java:1766)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:410)

Thanks,
Ajith

AJITH K.R

unread,
Jun 22, 2016, 9:20:18 PM6/22/16
to Jenkins Users
Any more help in this please.
Reply all
Reply to author
Forward
0 new messages