• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • ssh-steps-plugin
    • None
    • Jenkins 2.204.1
      Ubuntu 16.04.5 LTS

      I have an issue using an sshCommand with sudo set to true from within a pipeline.

      withCredentials([sshUserPrivateKey(credentialsId: credentials_id, keyFileVariable: 'JenkinsIdentity')]) {
      	script {
      		def remote = [name: server_name, host: host_name, knownHosts: remote_knownHosts, user: remote_user, timeoutSec: 1200, identityFile: JenkinsIdentity]
      		
      		// install application
      		sshCommand remote: remote, command: '/home/user/install.sh', sudo: true
      	}
      }
      

      The command executes on the remote server, but it's waiting forever. Probably waiting for user input.

      On the remote server i see this in processes:
      root 62610 62609 0 16:35 ? 00:00:00 sudo -S -p 4b0b21d6-23ab-4e47-b21e-8362bdf2c4d0 sh /home/user/install.sh

      It will only stop when i abort the jenkins job.

      Any ideas on what i can try?

          [JENKINS-60698] sshCommand with sudo: true waits forever

          To run sudo command the we need to provide username and password as the command would be waiting for an password as an input during the actual execution, it would waiting. Looks like you are using identifyFile so either switch it to use username password or add support for password less sudo access on these commands.

          Naresh Rayapati added a comment - To run sudo command the we need to provide username and password as the command would be waiting for an password as an input during the actual execution, it would waiting. Looks like you are using identifyFile so either switch it to use username password or add support for password less sudo access on these commands.

          I am also facing this issue. If the user does not have password-less sudo access, the pipeline is not prompting for the password.

           

          Here is my code

           

          def remote = [:]
          remote.name = 'test'
          remote.host = '10.0.0.1'
          remote.user = 'user'
          remote.password = 'password'
          remote.allowAnyHosts = true

          pipeline {
          agent any
          stages {
          stage('Run command') {
          steps

          { sshCommand remote: remote, command: 'sudo uptime' }

          }

          }
          }

          Unnikrishnan R added a comment - I am also facing this issue. If the user does not have password-less sudo access, the pipeline is not prompting for the password.   Here is my code   def remote = [:] remote.name = 'test' remote.host = '10.0.0.1' remote.user = 'user' remote.password = 'password' remote.allowAnyHosts = true pipeline { agent any stages { stage('Run command') { steps { sshCommand remote: remote, command: 'sudo uptime' } } } }

          Add sudo: true param to let that step know that it is sudo command:
          https://github.com/jenkinsci/ssh-steps-plugin#sshcommand

          sshCommand remote: remote, command: 'sudo uptime', sudo: true
          

          Naresh Rayapati added a comment - Add sudo: true param to let that step know that it is sudo command: https://github.com/jenkinsci/ssh-steps-plugin#sshcommand sshCommand remote: remote, command: 'sudo uptime' , sudo: true

          It does not prompt the password with the above options. Please find the attached screenshot.

          Unnikrishnan R added a comment - It does not prompt the password with the above options. Please find the attached screenshot.

          The prompt won't show up in Jenkins or even during the execution, while running the command when it prompts for the password, it provides during the runtime. Please make sure this user has permission to run the sudo commands. Try to run this command outside jenkins by logging into the box and make sure it works.

          Naresh Rayapati added a comment - The prompt won't show up in Jenkins or even during the execution, while running the command when it prompts for the password, it provides during the runtime. Please make sure this user has permission to run the sudo commands. Try to run this command outside jenkins by logging into the box and make sure it works.

          I can login and run sudo commands on the server directly. But when i execute the pipeline from Jenkins, it fails after few mins with below error.

          Is there any other dependency?
          Executing command on test[xxxxxxxxxxxxxxxx]: sudo uptime sudo: trued6663c80-6296-4886-82f3-f04a84657db3
          Failed command test#0 with status 1: sudo -S -p 'd6663c80-6296-4886-82f3-f04a84657db3' sudo uptime[Pipeline] }[Pipeline] // stage[Pipeline] }[Pipeline] // node[Pipeline] End of Pipelineorg.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: sudo -S -p 'd6663c80-6296-4886-82f3-f04a84657db3' sudo uptime
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
          at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
          at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
          at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255)
          at org.hidetake.groovy.ssh.session.execution.SudoHelper.execute(SudoHelper.groovy:76)
          at org.hidetake.groovy.ssh.session.execution.SudoHelper$execute.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
          at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper.executeSudo(Sudo.groovy:18)
          at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper$executeSudo$0.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)
          at org.hidetake.groovy.ssh.session.SessionHandler.executeSudo(SessionHandler.groovy)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169)
          at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
          at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper.executeSudo(Sudo.groovy)
          at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper$executeSudo.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
          at org.hidetake.groovy.ssh.session.SessionHandler.executeSudo(SessionHandler.groovy)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
          at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
          at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
          at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
          at org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy:180)
          at org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
          at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
          at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
          at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
          at org.hidetake.groovy.ssh.util.Utility.callWithDelegate(Utility.groovy:17)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:498)
          at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
          at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
          at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46)
          at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
          at org.hidetake.groovy.ssh.session.SessionTask.wetRun(SessionTask.groovy:64)
          at org.hidetake.groovy.ssh.session.SessionTask.call(SessionTask.groovy:48)
          at java_util_concurrent_Callable$call.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
          at org.hidetake.groovy.ssh.core.Service.run(Service.groovy:81)
          at org.hidetake.groovy.ssh.core.Service$run$0.call(Unknown Source)
          at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
          at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
          at org.jenkinsci.plugins.sshsteps.SSHService.executeCommand(SSHService.groovy:177)
          at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution$CommandCallable.execute(CommandStep.java:84)
          at org.jenkinsci.plugins.sshsteps.util.SSHMasterToSlaveCallable.call(SSHMasterToSlaveCallable.java:32)
          at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
          at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72)
          at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
          at java.util.concurrent.FutureTask.run(FutureTask.java:266)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
          at java.lang.Thread.run(Thread.java:748)
          Finished: FAILURE
           

           

          Unnikrishnan R added a comment - I can login and run sudo commands on the server directly. But when i execute the pipeline from Jenkins, it fails after few mins with below error. Is there any other dependency? Executing command on test [xxxxxxxxxxxxxxxx] : sudo uptime sudo: trued6663c80-6296-4886-82f3-f04a84657db3 Failed command test#0 with status 1: sudo -S -p 'd6663c80-6296-4886-82f3-f04a84657db3' sudo uptime [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipelineorg.hidetake.groovy.ssh.session.BadExitStatusException: Command returned exit status 1: sudo -S -p 'd6663c80-6296-4886-82f3-f04a84657db3' sudo uptime at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83) at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77) at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:255) at org.hidetake.groovy.ssh.session.execution.SudoHelper.execute(SudoHelper.groovy:76) at org.hidetake.groovy.ssh.session.execution.SudoHelper$execute.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper.executeSudo(Sudo.groovy:18) at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper$executeSudo$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141) at org.hidetake.groovy.ssh.session.SessionHandler.executeSudo(SessionHandler.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:169) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper.executeSudo(Sudo.groovy) at org.hidetake.groovy.ssh.session.execution.Sudo$Trait$Helper$executeSudo.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133) at org.hidetake.groovy.ssh.session.SessionHandler.executeSudo(SessionHandler.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166) at org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy:180) at org.jenkinsci.plugins.sshsteps.SSHService$_executeCommand_closure3$_closure13.doCall(SSHService.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57) at org.hidetake.groovy.ssh.util.Utility.callWithDelegate(Utility.groovy:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.invoke(StaticMetaMethodSite.java:46) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.callStatic(StaticMetaMethodSite.java:102) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214) at org.hidetake.groovy.ssh.session.SessionTask.wetRun(SessionTask.groovy:64) at org.hidetake.groovy.ssh.session.SessionTask.call(SessionTask.groovy:48) at java_util_concurrent_Callable$call.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.hidetake.groovy.ssh.core.Service.run(Service.groovy:81) at org.hidetake.groovy.ssh.core.Service$run$0.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at org.jenkinsci.plugins.sshsteps.SSHService.executeCommand(SSHService.groovy:177) at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution$CommandCallable.execute(CommandStep.java:84) at org.jenkinsci.plugins.sshsteps.util.SSHMasterToSlaveCallable.call(SSHMasterToSlaveCallable.java:32) at hudson.remoting.LocalChannel.call(LocalChannel.java:45) at org.jenkinsci.plugins.sshsteps.steps.CommandStep$Execution.run(CommandStep.java:72) at org.jenkinsci.plugins.sshsteps.util.SSHStepExecution.lambda$start$0(SSHStepExecution.java:84) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Finished: FAILURE    

          Nils Berg added a comment -

          I am experiencing the same Issue, the user has rights to execute any command via sudo, the password was provided correctly. Login to the remote machine is successful, but when I try to use any command with "sudo: true" the execution hangs forever.

          Here is the code I used:

           

          def remote = [:]
           remote.name = 'app.example.org'
           remote.host = 'app.example.org'
           remote.user = 'user'
           remote.password = 'pass'
           remote.allowAnyHosts = true
           
          def applicationName = "app"
          def baseDirectory = "/opt/example/" + applicationName
          Map deploymentDirectories = [backupFolder: baseDirectory + "/backup", tempFolder: baseDirectory + "/temp", migrationFolder: baseDirectory + "/migration", configFolder: baseDirectory + "/config"]
          
          pipeline {
              agent { label 'master' }
              stages {
                  stage('Example Stage') {
                      steps {
                          timestamps {
                              script {
                                  sshCommand remote: remote, command: "mkdir -p ${baseDirectory}" // <- Working
                                  deploymentDirectories.each {
                                      sshCommand remote: remote, command: "sudo mkdir -p ${it.value}", sudo: true // <- stuck forever
                                  }                    
                              }
                          }
                      }
                  }
              }
          }
          

           

           

          Nils Berg added a comment - I am experiencing the same Issue, the user has rights to execute any command via sudo, the password was provided correctly. Login to the remote machine is successful, but when I try to use any command with "sudo: true" the execution hangs forever. Here is the code I used:   def remote = [:] remote.name = 'app.example.org' remote.host = 'app.example.org' remote.user = 'user' remote.password = 'pass' remote.allowAnyHosts = true def applicationName = "app" def baseDirectory = "/opt/example/" + applicationName Map deploymentDirectories = [backupFolder: baseDirectory + "/backup" , tempFolder: baseDirectory + "/temp" , migrationFolder: baseDirectory + "/migration" , configFolder: baseDirectory + "/config" ] pipeline { agent { label 'master' } stages { stage( 'Example Stage' ) { steps { timestamps { script { sshCommand remote: remote, command: "mkdir -p ${baseDirectory}" // <- Working deploymentDirectories.each { sshCommand remote: remote, command: "sudo mkdir -p ${it.value}" , sudo: true // <- stuck forever } } } } } } }    

          Barna Szabó added a comment -

          Hello, I have the same issue on Ubuntu 16.04.6 LTS.

          I had an older Jenkis and jobs working for many years, and after update to version 2.249.2 it appears the same problem.

          Barna Szabó added a comment - Hello, I have the same issue on Ubuntu 16.04.6 LTS. I had an older Jenkis and jobs working for many years, and after update to version 2.249.2 it appears the same problem.

          David added a comment -

          Here is what worked for me. I found this note in the CHANGELOG on GitHub for version 2.0.0:

           Caution sshCommand with sudo:true param also requires pty:true on remote config with this upgrade. (This is only applicable for few platforms like Linux so apply this accordingly)

           

          When I set pty , it worked. I wasn't prompted interactively to enter a password, it just used the one I provided.

          David added a comment - Here is what worked for me. I found this note in the CHANGELOG on GitHub for version 2.0.0:  Caution sshCommand with sudo:true param also requires pty:true on remote config with this upgrade. (This is only applicable for few platforms like Linux so apply this accordingly)   When I set pty , it worked. I wasn't prompted interactively to enter a password, it just used the one I provided.

          Padmahasa added a comment -

          Padmahasa added a comment - The solution found by David ( https://issues.jenkins.io/browse/JENKINS-60698?focusedCommentId=405061&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-405061 ) to set remote.pty  =true worked for me as well.   Thank you very much arlatoroida .

            nrayapati Naresh Rayapati
            nickhardy Nick Hardy
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: