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的坑給填完了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM