問題背景:
jenkins服務器發布代碼后需要執行刪除緩存的操作
ssh -p222 eus_pe_devadmin@1.1.1.1 "sudo rm -rf /dev/shm/nginx/hipdf/cache/*"
分析:
要讓jenkins能刪除遠程服務器上的緩存,需要配置免秘鑰打通
為避免權限過大,使用 eus_pe_devadmin 操作,即jenkins服務器上運行tomcat服務的apache用戶操作遠程 eus_pe_devadmin 用戶來刪除緩存
需要把運行jenkins程序的apache用戶公鑰拷貝到遠程服務器的目標用戶: /home/eus_pe_devadmin/.ssh/authorized_keys 中,發現apache用戶下沒有公鑰,於是手動ssh-key-gen生成了新的私鑰和公鑰
發現jenkins不能連接git代碼倉庫,所有的代碼都不能發布
報錯:
Failed to connect to repository : Command "/usr/bin/git ls-remote -h git@xx.com.git HEAD" returned status code 128:
stdout:
stderr: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
jenkins發布報錯
Please make sure you have the correct access rights
and the repository exists.
解決辦法:
登錄連接git倉庫的賬號,配置對應的ssh_key即可