jenkins整合gitlab時,Source Code Management添加gitlab倉庫路徑無論怎么嘗試都報如下兩個異常:
Failed to connect to repository : Command "git ls-remote -h git@xxxxx.com:xxx/dev_test.git HEAD" returned status code 128: stdout: stderr: Permission denied, please tryagain. Permission denied, please try again. Permission denied(publickey,gssapi-keyex,gssapi-with-mic,password). fatal: The remote end hung up unexpectedly
或
Failed to connect to repository : Command "/usr/local/git/bin/git -c core.askpass=true ls-remote -h http://www.xxx.com/gitlab/root/test.git HEAD" returned status code 128: stdout: stderr: fatal: Unable to find remote helper for 'http'
原因是:由於運行jenkins用戶沒有生成ssh私鑰,且沒有添加gitlab中。因此導致了如上異常。
生成ssh私鑰
ssh-keygen -t rsa -C "admin@example.com"
運行上述命令,並一路回車即可生成相應的私鑰。
將私鑰添加到gitlab
cat ~/.ssh/id_rsa.pub
將所有內容添加到gitlab-->Profile Settings-->SSH Keys-->Add an SSH key。
保存后重啟jenkins即可。