How to make a shell script quieter?

3,957 views
Skip to first unread message

David Aldrich

unread,
Apr 11, 2012, 5:15:49 AM4/11/12
to jenkins...@googlegroups.com

Hi

 

Some of my Jenkins jobs run bash shell scripts that are stored in Subversion.  The scripts are quite complex and may contain ‘for’ loops:

 

For example:

 

for Simulation in $SimulationsList_1

do

    cd $SIM_PATH_1/$Simulation

    zip -qr $SIM_PATH_1/$Simulation'_'$BUILD_NUMBER *

done

 

The Jenkins console output for such a loop is quite noisy.  For example, the ‘for’ statement is printed in every iteration.

 

Is there a way of making a script command silent?  For example, I would like to make the line containing ‘for’ silent.

 

Best regards

 

David

 

wohauser

unread,
Apr 11, 2012, 5:32:51 AM4/11/12
to jenkins...@googlegroups.com
Jenkins build steps call shell scripts with the option -x, this enables the tracing of the shell script.

use "set +x" in your shell script or at the beginning of the build step script to turn the tracing off again.
Normally the "noisiness" is very helpful to check if the build has done properly

Regards
Wolfgang

Zoltan Gyarmati

unread,
Apr 11, 2012, 5:42:10 AM4/11/12
to jenkins...@googlegroups.com
Hi,

it's more a bash question than jenkins, but the point is, Jenkins calls the bash with -x option enabled, which also prints the invoked commands, with a "+" prefix
You can disable it with with the "set +x" command form your script, try it with this snippet:

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
#!/bin/bash -x

echo "prints the command as well"

set +x
echo "this just prints the echo's output"

set -x
echo "also prints the command itself again"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""


br,
Zoltan

David Aldrich

unread,
Apr 11, 2012, 6:33:14 AM4/11/12
to jenkins...@googlegroups.com

Thanks for both answers,

 

David

 

Click here to report this email as spam.

Gábor Garami

unread,
Apr 11, 2012, 6:35:28 AM4/11/12
to jenkins...@googlegroups.com

And you can shut up zip completelly with -qq

Garami Gábor
gabor....@hron.me
Skype: hron84
Tel: +36 20 235 9621

Sent from my T-Mobile G2
Ezt a levelet telefonról adták fel, ékezethibákat tartalmazhat.

Sami Tikka

unread,
Apr 11, 2012, 4:00:38 PM4/11/12
to jenkins...@googlegroups.com
And I'd like to add:

If the first line of a shell build step starts with hashbang (#!),
then Jenkins will simply drop the script as is into a tmp file and
execute it.

Otherwise Jenkins copies the script into a tmp file and executes it
using /bin/sh -xe /tmp/somefilename

And /bin/sh, is just the shell used by Jenkins by default. You can
change the default under Manage Jenkins -> Configure System.

-- Sami

2012/4/11 Zoltan Gyarmati <zoltan....@blumsoft.eu>:

Reply all
Reply to author
Forward
0 new messages