disable/hide logging of shell script content to console log

14,955 views
Skip to first unread message

Bhushan Kittur

unread,
Oct 24, 2016, 11:31:29 AM10/24/16
to jenkins...@googlegroups.com

Hello Everyone,


I am using "Execute shell script on remote host using SSH" under Build section of the Job config with lines of shell script placed there.

And see all lines from the shell script are logged into Jenkins console log during job's execution. 

Ex:

tarted by user anonymous
[EnvInject] - Loading node environment variables.
Building in workspace ...
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.

executing script:
target_env="dev"
var1=${target_env}

key="test123"
branchName=dev_feature1
startDeploy()


case "$var1" in

dev ) 

.

.

.

esac


 So is there a way to disable/hide shell script contents from logging into Jenkins console output of the job.


Sent from Outlook

Teichner Peter

unread,
Oct 24, 2016, 11:35:03 AM10/24/16
to jenkins...@googlegroups.com

You can hide your output away from the script by redirecting the output to /dev/null but I think this the most you can do – the commands that you write will still be displayed.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/HK2PR03MB1857371344C566364709E32FA8A90%40HK2PR03MB1857.apcprd03.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Oct 24, 2016, 12:18:03 PM10/24/16
to Jenkins Users, peter.t...@nagra.com
Jenkins uses the shebang, by default

#!/bin/sh -xe

-x will prompt those verbose details, if you'd like to reset that you can set the default shebang in your shell build step with something like

#!/bin/sh -e

# add whatever you'd like to do

Cheers

Bhushan Kittur

unread,
Oct 24, 2016, 4:11:29 PM10/24/16
to Jenkins Users, peter.t...@nagra.com

Thanks for the response.

Tried with "#!/bin/sh -e". Still everything gets logged to console. 


 

Sent from Outlook




From: jenkins...@googlegroups.com <jenkins...@googlegroups.com> on behalf of Victor Martinez <victormar...@gmail.com>
Sent: Monday, October 24, 2016 9:48 PM
To: Jenkins Users
Cc: peter.t...@nagra.com
Subject: Re: disable/hide logging of shell script content to console log
 

Victor Martinez

unread,
Oct 24, 2016, 5:22:54 PM10/24/16
to Jenkins Users, peter.t...@nagra.com
The suggested shebang works as expected, see the below details:

Execute shell step based on #!/bin/sh -e

#!/bin/sh -e
echo hi
echo world

Console Output:

[example] $ /bin/sh -e /tmp/hudson8709802188364684962.sh
hi
world

Execute shell step based the default shebang

echo bye
echo world

Console Output:

[example] $ /bin/sh -xe /tmp/hudson8136234464915657626.sh
+ echo bye
bye
+ echo world
world

If the above shebang doesn't fit your requirements, you might consider to use the approach suggested by Teichner Peter 

Cheers

Bhushan Kittur

unread,
Oct 24, 2016, 5:54:58 PM10/24/16
to Jenkins Users, peter.t...@nagra.com

Thanks Victor. 

I assume you are running the shell commands on the same host machine (local). Did you try running on remote host ?

Here is the screenshot of the config I tired.




Sent from Outlook




Sent: Tuesday, October 25, 2016 2:52 AM

Sabari V L

unread,
Jun 12, 2018, 8:43:52 AM6/12/18
to Jenkins Users

Hi,

I am facing the same issue in Jenkins- Unable to suppress code being printed from the remote host. I could not find the solution from any blog. 

Can you please share the solution?   

Sabari V L

unread,
Jun 29, 2018, 3:58:53 PM6/29/18
to Jenkins Users
Well, I found the solution myself after googling it for a week. The issue is resolved in latest ssh plug-in version 2.6.1



Reply all
Reply to author
Forward
0 new messages