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]
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?
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.