Many times I have been on a jenkins script console wanting to do a shell script using the pipe character to chain calls together.
du -sh --max-depth=1 | sort -h
Jenkins Script console default scripting
The suggested way of doing things leaves much to be desired. It does give you groovy to do queries in but it is not very powerful.
println "uname -a".execute().text
Works for default simple single commands.
You cannot pipe a command to another and white space in directory names does not work.
println(['ls', '/tmp/folder with spaces'].execute().text)
This to allow folders with spaces by turning command into array of strings. You do not have to escape any spaces and it will be able to deal with it.
You cannot chain commands together
The better Jenkins script console command
println new ProcessBuilder( 'sh', '-c', 'du -h --max-depth=1 /var/foo/bar/ | sort -hr').redirectErrorStream(true).start().text
Can chain commands together
Have to escape whitespace in the java way with \\
println new ProcessBuilder( 'sh', '-c', 'du -h --max-depth=1 /var/foo/bar/folder\\ with\\ spaces | sort -hr').redirectErrorStream(true).start().text