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

5

19

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.

Charpentier answered 29/3, 2018 at 20:1 Comment(4)
I've noticed this too. It's not very useful. Short answer is, I don't think you can. Having implemented a plugin recently, I realised it is the display name for the pipeline step provided by the plugin that implements it. From here look for the getDisplayName() method: github.com/jenkinsci/workflow-basic-steps-plugin/blob/master/…Winn
Having the same issue and can't understand how 5 different lines print out with and without "Print Message" using echo.Ehling
Got into this same problem today... I noticed that if you call a step embedded into another shared library, all the statements print link that... Still investigating...Ehling
I'm here again... No signs of identifying the reasons why this happens...Ehling
B
7

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.

Brooke answered 5/11, 2018 at 18:50 Comment(0)
C
6

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.

Cockoftherock answered 23/5, 2019 at 17:51 Comment(0)
L
5

This is a known BlueOcean bug. The console output in the "classic" view interpolates variables correctly.

One workaround is to use the label parameter of the sh step:

def message = 'Hello World'
sh(script: "echo $message", label: message)
Lathrop answered 25/10, 2019 at 12:27 Comment(0)
T
1

I tried lots of things and seems the moment an environment variable is going to be displayed, it uses Print Message instead the text.

Therefor answered 21/5, 2018 at 19:1 Comment(0)
D
0

Another workaround would be to split the multiline string into an array and iterate over it :-

 String[] splitData = MULTI_LINE_STRING.split("\n");
     for (String eachSplit : splitData) {
         print(eachSplit);
      }
Dictator answered 20/1, 2022 at 23:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.