• 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

          Nick Hardy created issue -
          Nick Hardy made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]

          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.
          Naresh Rayapati made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Closed [ 6 ]
          Naresh Rayapati made changes -
          Resolution Original: Fixed [ 1 ]
          Status Original: Closed [ 6 ] New: Reopened [ 4 ]
          Naresh Rayapati made changes -
          Status Original: Reopened [ 4 ] New: Open [ 1 ]
          Naresh Rayapati made changes -
          Priority Original: Major [ 3 ] New: Minor [ 4 ]
          Naresh Rayapati made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: Open [ 1 ] New: Closed [ 6 ]

          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' } } } }
          Unnikrishnan R made changes -
          Resolution Original: Not A Defect [ 7 ]
          Status Original: Closed [ 6 ] New: Reopened [ 4 ]

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

              Created:
              Updated: