I have problematic use case:
I run Perl script with sudo
(from Jenkins):
sudo /usr/bin/perl /Users/snaggs/scripts/build_ios.pl ${BUILD_NUMBER} $Version $isPublish
The script runs several commands from CLI.
one of them is: $ pod spec lint
that fails with error: Cannot run pod as root
.
my $command = "/usr/local/bin/pod spec lint $POD_SPEC_FILE_ABS --verbose";
my $podResults = `$command`;
I don't want to remove sudo
.
How can I run specific command into the script without super user?
From
man sudo
:Use the
-u
flag to specify a user who isn't the superuser but has the permissions needed to do what you want to do.I wouldn't want Jenkins running test code as a regular user though (nor as the super user).
A better approach would be to set the ownership and permissions of the files and directories that Jenkins needs to access to grant permission using a group, make Jenkins run as a member of that group, and then remove
sudo
.