Recently i came accross a problem with jenkins to run a script as another user (you know because only some users can access/remove/create files)
Here is one, hopefully secured enough, solution, that i ran using ubuntu (should be very similar in other linux systems):
1. Create a custom password for jenkins user
sudo passwd jenkins
2. Add jenkins to sudoers list
sudo nano /etc/sudoer and add one line
jenkins ALL=(ALL) ALL
3. Create a file with the jenkins password inside and limit read access only to jenkins user
sudo su - jenkins
echo 'the_jenkins_password' > pwd
chmod 600 pwd
4. Execute your script
In your custom build create a free form build and select “Execute Shell” in build steps and in the box do:
cat /var/lib/jenkins/pwd | sudo -S su - another_user_name -c "sh /path/to/your/script.sh"
Et voila, your script start as your user name!