[Publish Over SSH] execCommand result to variable

Hi all,

I am using the Publish Over SSH plugin and I want to get the execCommand result to variable.

My Pipeline script :

	continueOnError: false, 
	failOnError: true,
	publishers: [
			verbose: true,
			configName: 'my_server',
			sshCredentials: [ username: params.Login, encryptedPassphrase: hudson.util.Secret.toString(params.Password) ],
			transfers: [ sshTransfer(execCommand: 'cat file.txt')]

env.file = execCommand.Result // Don't work, just example
echo 'env.file : ' + env.file

I want to stock value “execCommand” to “env.file” variable to use it in next stage.

An idea ?

Thank you :slight_smile:

So I don’t know anything about that plugin specifically, but You can do it via ssh-agent plugin and sh/bat/powershell. Though I’m not sure how you’d do username/password via parameters. I’d do credential selector instead.

sshagent(credentials: ['ssh-credentials-id']) {
  sh("scp file.txt my_server:file.txt") // for the publisher step?
  env.file = sh(returnStdout: true, script="ssh myserver cat file.txt").trim()
  echo 'env.file : ' + env.file