Jenkins Pipeline code to run remote shell scripts

692 views
Skip to first unread message

Arianrhod

unread,
Sep 14, 2018, 11:50:08 AM9/14/18
to Jenkins Users
Hi, I have to run two shell scripts on a remote server as part of a pipeline job (scripted, not via the GUI).  

They're both run on the same remote server, but one has to run when the first finishes, and they run as different users.  There is a 'jenkins' user account that has creds in the Jenkins creds store, that has full sudo access on all remote servers.

Shell script one has to be run as user abc, shell script two has to be run as root.

I have the sshAgent plugin on my Jenkins server, but cannot install any new plugins.

Can anyone give me any idea how this can be achieved, please ... I have been trawling through endless Google pages for over a week trying to figure it out, and drawing a blank.  I'm completely new to scripting jenkinsfiles!

thanks

David Karr

unread,
Sep 16, 2018, 1:56:16 AM9/16/18
to Jenkins Users
I might be missing something simple, but I would think you'd just use the "sh" pipeline step and run "ssh" with the remote command line to run.


thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/859367d8-2038-4ef4-9b7c-c25e9ed12d6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arianrhod

unread,
Sep 17, 2018, 7:51:47 AM9/17/18
to Jenkins Users
Thanks David, I'm sure you're probably right but I've found so many different versions of what the 'simple' answer is that I have no real idea of the correct syntax for the command.  Referencing credentials that are already stored within the Jenkins store, for example; some say this is necessary, some say not, and all have different angles on how this should be specified.  Even the plugin page isn't really clear on the correct syntax, hence my question here.

thanks

David Karr

unread,
Sep 17, 2018, 1:54:56 PM9/17/18
to Jenkins Users
On Mon, Sep 17, 2018 at 4:51 AM Arianrhod <helen....@gmail.com> wrote:
Thanks David, I'm sure you're probably right but I've found so many different versions of what the 'simple' answer is that I have no real idea of the correct syntax for the command.  Referencing credentials that are already stored within the Jenkins store, for example; some say this is necessary, some say not, and all have different angles on how this should be specified.  Even the plugin page isn't really clear on the correct syntax, hence my question here.

Looking at some old pipeline code of mine, it seems pretty clear that the "sshagent" wrapper is what you need to use. That takes a "credentials" property that refers to the credentials object stored in Jenkins, referring to the private key. Within that block, you can have a "sh" step calling ssh, which doesn't have to specify any credentials.


thanks

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages