def ret =sh (script: "ssh -A root@${list[0]}.${SIPDOMAIN} 'ls /tmp/tests-master/${list[0].minus(/2/)}/common -p | grep -v / | tr \'\\n\' ',' '", returnStdout: true) println ret for (job in entries(ret)) { println ${ret[0]} } Contents of the folder: ======================= lab-1:/tmp/tests-master/provisioning/common# ls anotherfile crontab_test Results in Jenkins: ==================== [Pipeline] echo a,otherfile cro,tab_test