All,
 I am trying to use  workflow-cps-global-lib-plugin to create some custom 
classes to be used within pipeline Job for some specific use case 
requirement. 

Instantiating the custom class within the pipeline Job. However anything 
logged within the our custom class is not posted in the Jenkins console.

As a hack, I have tried sending the Listener of the build to the custom 
class and logging it to it which solves the issue of messages not appearing 
in the console. However, message get jumbled up and down, as every step 
within the pipeline is executed in separate context and the log messages 
sent to from custom class ends up on top of all the messages, which defeats 
the purpose. see example below.

Is there any other alternatives that we could potentially use, such as 
creating a workflow step to execute the methods of our custom class, which 
passes the listener from the correct context.


Appreciate any suggestions, that could help us get over this hurdle as we 
are running tight timelines to this done. Thanks for your help.


Here is the sample code;

In Pipeline job definition:

def custom_class = new CustomClass(currentBuild.getRawBuild())
echo "starting Master"
custom_class.test_log()
echo "Test Echo"


CustomClass, logger is defined as below.
class CustomClass {
def jenkins_logger

CustomClass(rawbuild) {
this.jenkins_logger = rawbuild.listener.getLogger()
}
def test_log(msg) {
this.jenkins_logger.println(msg)
}
}



Jenkins Console Log

Started by user anonymous
Replayed #14[Pipeline] nodeRunning on master in 
/var/lib/jenkins/jobs/logger_test/workspace@3

Test Message from Custom Class method  --> This step is executing after echo 
step below, but message appears on the Top of the Log.[Pipeline] {[Pipeline] 
echostarting Master --> This is echo step within the Pipeline Job[Pipeline] 
echoTest Echo  -> this is executed after Custom class method.[Pipeline] 
}[Pipeline] // node[Pipeline] End of PipelineFinished: SUCCESS


-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/9a8351de-74e5-4e42-928d-0a86962d3ed3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to