[JIRA] (JENKINS-56768) Unable to switch to a sudo user using ssh pipeline

8 views
Skip to first unread message

gaddamanugu.anurag@gmail.com (JIRA)

unread,
Mar 26, 2019, 7:59:02 PM3/26/19
to jenkinsc...@googlegroups.com
Anurag GADDAMANUGU created an issue
 
Jenkins / Task JENKINS-56768
Unable to switch to a sudo user using ssh pipeline
Issue Type: Task Task
Assignee: Naresh Rayapati
Components: ssh-steps-plugin
Created: 2019-03-26 23:58
Environment: Production
Priority: Major Major
Reporter: Anurag GADDAMANUGU

My task is to perform certain operations on Linux server as a sudo user. 

Current Situation: Using the ssh pipeline plugin I am able to login into the remote server and run the command using sshCommand. 

 

Issue: To perform other operations I need to switch to a  sudo user  with a password.  I am unable to find if this is possible with this plugin.

Please refer to the below code and let us know you suggestions to the issue

 

def remote = [:]
remote.name = '<server name>'
remote.host = '<server host name>'
remote.user = '<userId>'
remote.password = '<password>'
remote.allowAnyHosts = true
remote.agent = true
node{
stage('Remote SSH')

{ sshCommand remote: remote, command: "ls lrt"   Able to Execute the pipeline until here sshCommand remote: remote, command: "sudo su <sudo Username>",sudo: true — Not sure if this is the right usage }

}

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

naresh.rayapati@gmail.com (JIRA)

unread,
Apr 28, 2019, 4:26:02 AM4/28/19
to jenkinsc...@googlegroups.com
Naresh Rayapati updated an issue
Change By: Naresh Rayapati
My task is to perform certain operations on Linux server as a sudo user. 

*Current Situation:* Using the ssh pipeline plugin I am able to login into the remote server and run the command using sshCommand. 

 

*Issue*: To perform other operations I need to switch to a  sudo user  with a *password*.  I am unable to find if this is possible with this plugin.


Please refer to the below code and let us know you suggestions to the issue

 
{code}
def remote = [:]
remote.name = '<server name>'
remote.host = '<server host name>'
remote.user = '<userId>'
remote.password = '<password>'
remote.allowAnyHosts = true
remote.agent = true
node{
stage('Remote SSH') {
sshCommand remote: remote, command: "ls lrt"   Able to Execute the pipeline until here
sshCommand remote: remote, command: "sudo su <sudo Username>",sudo: true — Not sure if this is the right usage
}
}

{code}

 

naresh.rayapati@gmail.com (JIRA)

unread,
Apr 28, 2019, 4:33:02 AM4/28/19
to jenkinsc...@googlegroups.com
Naresh Rayapati started work on Task JENKINS-56768
 
Change By: Naresh Rayapati
Status: Open In Progress

naresh.rayapati@gmail.com (JIRA)

unread,
Apr 28, 2019, 4:33:02 AM4/28/19
to jenkinsc...@googlegroups.com
Naresh Rayapati commented on Task JENKINS-56768
 
Re: Unable to switch to a sudo user using ssh pipeline

Given the password for the user configured for remote is same as the sudo Username, the example in the description works, which is very rare.

Why don't do try configuring the actual sudo user and password for the remote to execute these sudo commands?

def remote = [:]
 remote.name = '<server name>'
 remote.host = '<server host name>'
 remote.user = '<userId>'
 remote.password = '<password>'
 remote.allowAnyHosts = true
 remote.agent = true
 node {
  stage('Remote SSH'
) {
     sshCommand remote: remote, command: "ls lrt"   // This works.
     sshCommand remote: remote, command: "sudo ls -lrt", sudo: true // This should work too given userId as sudo access and configured as non passwordless sudo access (requires password for sudo commands)
   }
 }

naresh.rayapati@gmail.com (JIRA)

unread,
May 30, 2019, 12:05:02 PM5/30/19
to jenkinsc...@googlegroups.com

Anurag GADDAMANUGU Closing this request as it is been a while we don't have any updates. Please log a new ticket of reopen this one if you need more details.

naresh.rayapati@gmail.com (JIRA)

unread,
May 30, 2019, 12:05:03 PM5/30/19
to jenkinsc...@googlegroups.com
Naresh Rayapati closed an issue as Won't Fix
 
Change By: Naresh Rayapati
Status: In Progress Closed
Resolution: Won't Fix

mtarun523@gmail.com (JIRA)

unread,
Oct 23, 2019, 3:03:02 PM10/23/19
to jenkinsc...@googlegroups.com
Tharun Reddy commented on Task JENKINS-56768
 
Re: Unable to switch to a sudo user using ssh pipeline

Hello Naresh,

I am currently using SSH-steps plugin to run few commands. I am able to run most commands that do not require sudo, however when I run commands that require sudo, the pipeline hangs. I get error "org.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: sudo -S ......" The account i am connecting do not have passwordless sudo access. Do we need to have passwordless access?

Thanks,
Tharun

This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

naresh.rayapati@gmail.com (JIRA)

unread,
Oct 24, 2019, 7:35:03 AM10/24/19
to jenkinsc...@googlegroups.com

Tharun Reddy I hope you are adding sudo: true option for those commands? passwordless sudo access doesn't require that option.

Reply all
Reply to author
Forward
0 new messages