SSH在Jenkins中的使用

我们今天在迁移Jenkins的时候又出现无法调用私钥来获取oschina的git代码和使用scp拷贝无法验证的问题。我发现主要的问题实际上是关于ssh的问题,因为git和scp都是通过ssh来实现与远端服务器的通讯过程。
我总结有下面三个坑:
 
1. 当存在多个私钥(通常我们创建出来默认名称为: id_rsa 或者id_dsa )的时候如何处理?
比如我有两个私钥
  • id_rsa_oschina
  • id_dsa70
分别对应连接的服务器是git.oschina.net 和 192.168.88.70 linux服务器。
这种情况下,需要在ssh默认配置目录,c:\users\[username]\.ssh下创建一个config的文件,指定对应的服务器使用的identityfile

Host git.oschina.net

  IdentityFile ~/.ssh/id_rsa_oschina

Host 192.168.88.70

  IdentityFile ~/.ssh/id_dsa70

 
 
2. DSA协议不被认可
使用 
ssh -vT wzp@192.168.88.70
进行测试,发现其中
debug1: Skipping ssh-dss key /c/Users/UM_CI_BUILDER/.ssh/id_dsa70 for not in PubkeyAcceptedKeyTypes
 
因此,需要config文件中指定
 Host 192.168.88.70
   IdentityFile ~/.ssh/id_dsa70
   PubkeyAcceptedKeyTypes ssh-dss
 
3. 在jenkins中 使用 scp cas.war wzp@192.168.88.70:/home/wzp/ 提示unstable的编译结果。

E:\Jenkins_work\QA_UM_SSO\workspace\cas-server-webapp\target>scp cas.war wzp@192.168.88.70:/home/wzp/

E:\Jenkins_work\QA_UM_SSO\workspace\cas-server-webapp\target>exit 0

SSH: Connecting from host [WIN12FILESRV1]

SSH: Connecting with configuration [LINUX CAS SVR-80-Test] ... ERROR: Exception when publishing, exception message [Failed to read file - filename [C:\Users\UM_CI_BUILDER\.ssh\id_dsa] (relative to JENKINS_HOME if not absolute).

Message: [C:\Users\UM_CI_BUILDER\.ssh\id_dsa (The system cannot find the file specified)]] Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE

Finished: UNSTABLE

 

这个需要在jenkins全局配置,增加LINUX CAS SVR-80-Test 在publish over ssh中的定义。

 

 

好吧,终于把Jenkins发布到linux的坑给填完了。

posted on 2016-03-04 09:44  一望无际的南  阅读(14684)  评论(0编辑  收藏  举报

导航