0

While setting up deployment through jenkins for my django project, I got stuck where I had to restart apache2 service to reflect the new changes to the client side. I am not sure how to provide user password after running systemctl reload apache2.service command.

I tried below options but no luck.

1) systemctl reload apache2.service

Result:

Failed to reload apache2.service: Interactive authentication required.
See system logs and 'systemctl status apache2.service' for details.
Build step 'Execute shell' marked build as failure

2) sudo systemctl reload apache2.service

Result :

sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure 

3) Also not sure whether sshpass will help in this case

Attached screenshot taken from jenkins job.

Here is the screenshot taken from jenkins

1 Answers1

1

As noted in a comment before, you have an problem with permissions here.

I assume that your Jenkins instance is running under user "jenkins", which cannot execute admin (root) commands. So you need to login via SSH into the machine and make sure that the user "jenkins" can execute this command with sudo.

You can find help for editing the sudoers file here: How To Edit the Sudoers File on Ubuntu and CentOS. I would recommend you to only to allow certain commands.

If you decide that the "jenkins" user needs to enter a password use the following command:

echo password | sudo -S systemctl reload apache2.service

Of cause you should store that password in a secure way and mask it within the build. The Jenkins Credentials Plugin can help you with this.

crash
  • 603
  • 4
  • 11