Skip to content

Instantly share code, notes, and snippets.

@mucst
mucst / log-to-console-from-shared-lib-class.groovy
Last active February 9, 2024 07:01
How to println to console log from jenkins shared library class
/*
* If you develop a jenkins shared library, you might eventually face the issue described at:
* https://stackoverflow.com/questions/47320406/propagating-logs-in-shared-library-to-jenkins-job-console
*
* Many across the internet suggest to pass the "steps" object to the class as some (constructor) parameter, such as in
* https://www.jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps
*
* ... which works, however this might be difficult if there are many usages of the class where you "just" want to print something to
* the console, maybe just for some debugging purposes. Unfortunatelly standard java Logger (in the momemnt of writing this gist at least)
* does not work. A not so nice, however working solution can be the following.
pipeline {
agent none
options {
buildDiscarder logRotator(numToKeepStr: '10')
}
triggers {
eventTrigger jmespathQuery("repository.full_name")