I have a jenkins server which logs into my production server via ssh and is supposed to restart some services with systemctl restart myservice.serviceI've read similar issues and the most common solution was this:jenkins ALL = NOPASSWD: /bin/systemctl restart myservice.service, /bin/systemctl restart myservice2.serviceand insert it into the sudoers file.I have also added Defaults:jenkins !requirettyMy deploy file does this:sudo /bin/systemctl restart myservice.serviceand then despite my efforts I still get the following error:sudo: no tty present and no askpass program specifiedI've read about using -t when ssh'ing but I'm unsure how I would do that since I do multiple commands and some are not sudo commands.So does anybody have a good solution for letting jenkins restart my services? I would like to avoid jenkins using root as its primary user.Edit:This was an issue on my side. My jenkins ssh'd into another server and is not logged in as jenkins so I was changing permissions for the wrong user. The solution withjenkins ALL = NOPASSWD: /bin/systemctl restart myservice.service, /bin/systemctl restart myservice2.serviceworks fine aslong as its the right user.
Letting jenkins execute commands as root
ssh;sudo;systemd;root