在Jenkins管道中使用ssh、scp或sftp的ssh凭据

6fe3ivhb  于 2022-11-02  发布在  Jenkins
关注(0)|答案(2)|浏览(367)

我想使用scp/ssh上传一些文件到服务器。我发现我需要使用基于证书的身份验证,但问题是怎么做?我真正想做的是使用与git相同的证书-a存储在Jenkins中的带密码的ssh cert。但是,我不知道如何做--代码片段生成器没有明显的选项。
其他人是怎么做的?有没有一个未公开的特性可以做到这一点?

wgx48brx

wgx48brx1#

withCredentials([sshUserPrivateKey(credentialsId: "yourkeyid", keyFileVariable: 'keyfile')]) {
       stage('scp-f/b') {
        sh 'scp -i ${keyfile} do sth here'
       }
   }

也许这就是你想要的。安装Credentials Plugin
Credentials Binding Plugin。添加一些凭据,然后您将获得“yourkeyid”,将此凭据绑定到keyFileVariable、passphraseVariable等。
更多的细节和文档可以在Jenkins Credentials Binding PluginCredentials Binding Plugin docsCredentials PluginSSH Pipeline Steps插件的Github站点上找到

vfhzx4xs

vfhzx4xs2#

如果你安装了SSH Agent plugin,你可以使用ssh-agent pipeline步骤来运行一个shell脚本,并激活一个ssh代理。ssh-agent获取一个Jenkins凭证ID(一个带密码的ssh证书,就像你为git所做的那样)。

相关问题