Search code examples
linuxbashjenkinssshredhat

How to use Sudo with a Jenkins bash script over SSH?


I have a physical machine (Win7) and a virtual machine (Red Hat) sharing a network. I am executing a bash script as a Jenkins job using the SSH plugin for Jenkins to deploy an application from the physical machine to the virtual machine.

I cannot use Root users due to security policy on the machine I want the script executed on and am instead limited to using standard users with sudo access.

However, I want the script to run without interruption (I don't think Jenkins even allows you to enter user passwords when running bash scripts? Also, this doesn't seem like best practice anyway).

Is there any method of bypassing the sudo request or configuration of the script that would allow this process to run the way I wish?


Solution

  • You can use a NOPASSWD directive in /etc/sudoers; see the sudoers manual page.

    If that is not possible, you can always use expect to feed the password (stored somewhere in the account) to the sudo process. This is probably against your security policy as well. You need to talk to the people who make the policy for advice on how you can automate these jobs (“digital transformation” and all that).