The problem is that your script uses sudo
at some point. The usual way around is to add the script that requires you to use sudo
to the sudoers.
Example: in your script you use sudo service apache2 reload
, now create a bash script containing that line and add that script to the sudoers file.
New script name: /home/quaser/restart-apache.sh
Use: visudo
Add at bottom of the file:
jenkins ALL=(ALL) NOPASSWD: /home/quaser/restart-apache.sh
Now, in your script change: sudo service apache restart
to sudo /home/quaser/restart-apache.sh
and you should not be asked for a password.