user1434702
user1434702

Reputation: 829

jenkins how to use ssh-agent in docker

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.

Upvotes: 0

Views: 1621

Answers (1)

Thanh Nguyen Van
Thanh Nguyen Van

Reputation: 11752

You should use:

sh 'ssh -o StrictHostKeyChecking=no -l yunwei x.x.x.x pwd && whoami && cmd...'

Upvotes: 1

Related Questions