【问题标题】:jenkins how to use ssh-agent in dockerjenkins 如何在 docker 中使用 ssh-agent
【发布时间】:2020-12-25 14:33:25
【问题描述】:

我的 jenkins 在 docker 中运行,我编写了一个演示来使用 ssh-agent 远程控制我的服务器。

这是我的管道

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'
                }
            }
        }
    }
}

输出

看起来 pwdwhoami 命令仍在 jenkins docker 中运行,而不是我的服务器。我不知道如何使用这个插件,我在ssh-agent 文档中找不到任何用法。

【问题讨论】:

    标签: jenkins ssh-agent


    【解决方案1】:

    你应该使用:

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

    【讨论】:

      猜你喜欢
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-18
      • 2017-09-17
      • 2023-03-16
      相关资源
      最近更新 更多