Disable standard output from Jenkins pipeline:

8,669 views
Skip to first unread message

Geethalakshmi Ramachandran

unread,
Feb 16, 2017, 11:23:41 AM2/16/17
to Jenkins Users
A jenkins pipeline calls an API that returns metrics and prints it in the console output with formatting. However, Jenkins pipeline prints standard output for each command like below: How to disable this or turn it off?

Hide quoted text

[Pipeline] sh

[Rel _pipeline] Running shell script

def pipelineUtil=null

fileLoader.withGit('ssh://git@test:7999/test/test.git',

test,

'..,

'groovy')

{

pUtil = fileLoader.load('src/pipeline/test-utils')

}

pUtil.getTest("TEST")

test-utils.groovy

void getTest(String test) {

stage "Test"

node ('groovy')

{

sh "set +x"

mysh "curl call some api"

mysh 'echo "***********TEST************"'

mysh 'echo "Overall : "'

}

}

def mysh(cmd) {

sh('#!/bin/sh -e\n' + cmd)

}

return this;

Output :

[Pipeline] sh

[Rel _pipeline] Running shell script

***********TEST ************

[Pipeline] sh

[Rel_ pipeline] Running shell script

Overall :

David Karr

unread,
Feb 19, 2017, 12:25:51 PM2/19/17
to jenkins...@googlegroups.com
On Thu, Feb 16, 2017 at 8:23 AM, Geethalakshmi Ramachandran
<geethalakshmi...@gmail.com> wrote:
> A jenkins pipeline calls an API that returns metrics and prints it in the console output with formatting. However, Jenkins pipeline prints standard output for each command like below: How to disable this or turn it off?

If you want to control how or whether stdout is emitted from a "sh"
step, instead of calling it like this:
----------
sh "command line"
---------

Do:
----
sh returnStdout: true; script: "command line"
----

I suppose you could set that to "false" also,but I've never done that.

Jean-Marc Taillant

unread,
Nov 16, 2018, 3:46:17 AM11/16/18
to Jenkins Users
In fact, from Jenkins doc:

returnStdout

If checked, standard output from the task is returned as the step value as a String, rather than being printed to the build log. (Standard error, if any, will still be printed to the log.) You will often want to call .trim() on the result to strip off a trailing newline.
Reply all
Reply to author
Forward
0 new messages