Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I force Jenkins Blue Ocean to display print output instead of "Print Message"?

In the below screenshot some debug entries display the output text (with - Print Message at the end) while others simply display Print Message. To view these you have to expand the step to see the output.

Jenkins Blue Ocean Output

All lines are using the format print "TEXT HERE". I've tried using print, println, and echo. All have the same output.

Why do these sometimes display the message, while others force it into a collapsed section? Is it possible to configure this to always show? The normal non-Blue Ocean Jenkins interface displays fine but there is a lot of verbosity.

like image 333
Caesar Kabalan Avatar asked Mar 29 '18 20:03

Caesar Kabalan


People also ask

How do I switch to blue ocean Jenkins?

Accessing Blue Ocean Once a Jenkins environment has Blue Ocean installed and you log in to the Jenkins classic UI, you can access the Blue Ocean UI by selecting Open Blue Ocean on the left side of the screen. Alternatively, you can access Blue Ocean directly by appending /blue to the end of your Jenkins server's URL.

What is Blue Ocean plugin in Jenkins?

"" Blue Ocean is a new user experience for Jenkins based on a personalizable, modern design that allows users to graphically create, visualize and diagnose Continuous Delivery (CD) Pipelines ""

How do I get out of stage in Jenkins pipeline?

Alternatively you can call error(String message) step to stop the pipeline and set its status to FAILED . For example, if your stage 1 calls error(msg) step like: stage("Stage 1") { steps { script { error "This pipeline stops here!" } } }


2 Answers

This seems to be a known issue: https://issues.jenkins-ci.org/browse/JENKINS-53649

It looks like that BlueOcean does not handle the Groovy GStrings correctly. This is what I've observed:

A simple:

echo "hello world"

will work as expected and will display correctly. Whereas a templated string with variables, like:

echo "hello ${some_variable}"

will hide the message under a "Print Message" dropdown.

See also this answer.

like image 98
Hüda Avatar answered Sep 28 '22 03:09

Hüda


It appears that if echo uses a variable with value from params or environment (i.e. "params.*"), then step label gets "Print message" name instead of actual value being echoed. It does not matter if the variable itself is a String or not. Even explicitly converting the params value to String does not help.

String param_str
String text_var_2

parameters {
    string(name: 'str_param', defaultValue: 'no value')
}

                param_str = params.str_param.toString()

                echo "string text in double quotes is ${param_str}"
                echo "simple quoted string is here"
                echo 'simple quoted string is here' 
                echo 'Single quoted with str ' + param_str + ' is here'
                echo param_str                    
                text_var_2 = 'Single quoted str ' + param_str + ' combined' 
                echo "GString global text2 is ${text_var_2}" 
                echo 'String global text2 is' +  text_var_2

BlueOcean shows simple quoted strings in step label, but everything else as "Print message".

BlueOcean output

Note that 'normal' variables (strings, integers) are not included into this example, but they are also shown in the label normally. So if you have a code like this

def text_str = 'Some string'
def int_var = 1+2
echo text_str + ' is here'
echo int_var

These will be shown on the label.

And indeed it appears to be a known Jenkins issue as stated in a previous answer.

like image 37
Roman Komarov Avatar answered Sep 28 '22 03:09

Roman Komarov