I have a jenkins setup on my server that has automatically created the jenkins
user, which is used for its os-operations. However, I need Jenkins to stop and start a service (via systemctl
) after a specific build has been completed.
My current script (that gets executed after a build of myapp
) looks like this:
sudo systemctl stop myapp
rm -f /opt/myapp/myapp.jar
mv target/myapp.jar /opt/myapp
sudo systemctl start myapp
To make this work, I simply added the jenkins
user to the sudoers file for all commands without password prompt:
jenkins ALL=(ALL:ALL) NOPASSWD: ALL
Is it safe to do this? What vulnerabilities do I expose myself to? Is there a better way to do this? If yes, how?
0 Answers