Sudo to unix server from Jenkins(windows)

52 views
Skip to first unread message

Prasu S

unread,
Mar 13, 2019, 3:52:21 PM3/13/19
to Jenkins Developers
We would like to run a restart script on Unix server(test) from Jenkins(windows) using sudo commands? Is this possible in Jenkins? What are the steps involved? Thanks in Advance 

Mark Waite

unread,
Mar 13, 2019, 4:48:32 PM3/13/19
to jenkinsci-dev
This is a Jenkins user question rather than a Jenkins dev question.  The Jenkins developer list is used for discussions of developing things for Jenkins, not for discussion of ways to use Jenkins to develop other things.

In your case, the answer is, yes, you can run a script on a Unix server from Jenkins on Windows.

You'll need a program that will allow you to run the 'ssh' command on Windows and have it run the 'sudo /sbin/shutdown -r now' command.  Git for Windows provides ssh.  Windows subsystem for Linux provides ssh.  The chocolatey package manager for Windows includes a Win32 OpenSSH.  Cygwin provides ssh.  I'm sure there are others as well.

The user on the remote Linux system needs to be configured to allow the /sbin/shutdown script to be run from sudo.  Refer to the 'sudo' man page and other online guides for sudo configuration instructions.

If those instructions are not sufficient to answer your question, please ask the question on the Jenkins users list.  There are more people on that list than on this list and they are more likely to have dealt with this type of question.

Mark Waite

On Wed, Mar 13, 2019 at 1:52 PM Prasu S <s.p...@gmail.com> wrote:
We would like to run a restart script on Unix server(test) from Jenkins(windows) using sudo commands? Is this possible in Jenkins? What are the steps involved? Thanks in Advance 

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/46863013-c7b9-48ad-9243-744b6bc1465a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Thanks!
Mark Waite

Jim Klimov

unread,
Mar 14, 2019, 5:10:22 AM3/14/19
to Prasu S, Jenkins Developers
More or less same as you would do it manually: ssh onto the server (name + pass, or name + sshkey) as a certain unprivileged user; have /etc/sudoers set up on the server to allow needed operations (or "ALL") to this user, and have a shell step calling sudo and those commands. On Jenkins side, you can use SSH Agent plugin to export one or more credentials (e.g. username + ssh key) saved in Jenkins master config so subsequent ssh commands in the job would use those safely to log into the server.

Jim
--
Typos courtesy of K-9 Mail on my Android

Prasu S

unread,
Mar 19, 2019, 11:11:14 AM3/19/19
to Jenkins Developers
Oops.. Sorry , I did not realize I posted this in Jenkins Developers group.

Thanks for your response.

Prasu S

unread,
Mar 19, 2019, 11:12:01 AM3/19/19
to Jenkins Developers
Thank you Jim for your response. It worked !
Reply all
Reply to author
Forward
0 new messages