Skip to content
Advertisement

Jenkins adding single quotes to bash shell script

My shell script looks like this:

#!/bin/bash
USER=$1
sudo rm -rf /home/$USER/system/logs/*
exit 0

It’s checked into cvs in a shell folder, Jenkins is configured to execute it on a Linux machine via a job with ‘Execute Shell’ build step:

bash -ex shell/clear-logs.sh myuser

But Jenkins is wrapping the whole sudo line in single quotes which results in my log files not been deleted (although the Jenkins job passes successfully):

[workspace] $ /bin/sh -xe /tmp/hudson7785398405733321556.sh
+ bash -ex shell/clear-logs.sh myuser
+ USER=myuser
+ sudo rm -rf '/home/myuser/system/logs/*'
+ exit 0

Any ideas why Jenkins is doing this? If I call the script from the Jenkins workspace location as the root user, then it works fine.

EDIT:

I have the same shell script, in different cvs modules, being executed by Jenkins on the same linux server. Have created a new job, either as freestyle or by copying an existing job where this works, but makes no difference.

Advertisement

Answer

Okay, seemed to have resolved this by adding the ‘jenkins’ user to the ‘myuser’ group and restarting the jenkins service. If the logs directory is empty, then Jenkins console output does report the path in single quotes, as no files found. But run the job a second time where there are files, and no single quotes, files correctly deleted.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement