I am running a shell script within the Jenkins pipeline and i want to print into a text file latest files names column created by date, i dont want want to print time & date column etc, just anything after 9 which are files names and print to into a txt file..
codes are as below:
Note: when i run those commands in bash all work fine, \ is added as Jenkins does not seems to like the $ without the dollar sign all run fine in shell.
out put in shell is like this:
bash.sh
home
testfile.txt
blabla.csv
rtyuioiuytrty.xml
like above I would like to be printed in Jenkinsfile. Jenkins does not seem to like to run those codes as below: I also tried this loop
node ('node') {
stage ('SSH To server') {
sshagent(credentials: ['sshkey']) {
script {
sh"""ssh -o StrictHostKeyChecking=no user@servername << EOF
if [ \$? -ne 0 ]; then
echo " Error while connecting SSH "
exit 1
fi
cd ${SOURCE_PATH}
if [ \$? -ne 0 ]; then
echo "Error while doing change directory \${SOURCE_PATH} "
exit 1
fi
ls -lrt | grep "$(date '+%b %e')" |awk '{ s =""; for (i = 9; i <= NF; i++) s = s $i " "; print }'
exit
EOF
"""