0

My jenkins is run in docker, I write a demo to remote my server with ssh-agent.

Here is my pipeline

pipeline {
    agent any

    stages {
        stage('Hello') {
            steps {
                sshagent (credentials: ['hehu']) {
                    sh 'ssh -o StrictHostKeyChecking=no -l yunwei xxx.xxx.xx.25 -a'
                    sh 'pwd'
                    sh 'whoami'
                }
            }
        }
    }
}

Output enter image description here

It looks like pwd and whoami command still run in jenkins docker not my server. I have no idea how to use this plugin, I can't find any usage from ssh-agent document.

user1434702
  • 817
  • 1
  • 14
  • 33

1 Answers1

1

You should use:

sh 'ssh -o StrictHostKeyChecking=no -l yunwei x.x.x.x pwd && whoami && cmd...'
Thanh Nguyen Van
  • 10,292
  • 6
  • 35
  • 53