Docker:pipeline編寫基本技巧- jenkins配置經過免交互方式拉取git源碼管理倉庫的代碼

工做中,從git倉庫拉取代碼有2種方式:交互式和非交互式html

什麼是交互式?就是拉取須要權限才能訪問的代碼時,須要輸入密碼linux

免交互式呢? 是經過密鑰,私鑰的方式,讓服務端信任客戶端,產生信任後,任何一次客戶端向服務端發起的請求時,不須要密碼,而是直接進行讀寫等操做。git

在持續集成中,jenkins須要去git代碼倉庫拉取代碼,在這個過程當中不方便交互式的輸入代碼,因此採用免交互式會比較方便。服務器

密鑰私鑰的生成和使用:微信

在客戶機linux機器上 ssh-keygen 一路回車運維

[root@192 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:llzcheb6UtbggaOnU6FTjssrLTIM5CQ5FjsnBq2zo5I root@192.168.1.40
The key's randomart image is:
+---[RSA 2048]----+
| .           ..  |
|...      . .o.   |
|.oo       o+.    |
|**o.   . o= +    |
|oO+     S* = +   |
|o o    .= = + .  |
|.o o   o * +     |
|E   + o * . .    |
|.    o o.o .     |
+----[SHA256]-----+
[root@192 ~]# ls .ssh/
id_rsa  id_rsa.pub  known_hosts

#經過ssh-copy-id命令將/root/.ssh/id_rsa.pub公鑰copy到192.168.1.30git源碼管理服務器上dom

[root@192 ~]# ssh-copy-id git@192.168.1.30
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
git@192.168.1.30's password: ssh

 
 

Number of key(s) added: 1ide

 
 

Now try logging into the machine, with: "ssh 'git@192.168.1.30'"
and check to make sure that only the key(s) you wanted were added.測試

 

 

到192.168.1.30git源碼管理服務器上,查看id_rsa.pub存放到了哪裏

[root@192 ~]# su - git
[git@192 ~]$ cat .ssh/authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPW1GD64WQr/1WdklohJrS35i3MS7Om2m9vXlDW/ZuvuucYiSzEiI9Thr3ooPBlavLRofh/oS3xzu+jHydm9hY20IV73Kmua3BWw3eMLUT6PXs2fvpGpspx9doVmJZ6B4IGN/4VYoFUPTYpy+WxxcqkxPeMQrZ5mcemzlUkB6GcSmNEI2U0lP4z7h+H0i+JvoVd7CF7FCAiYLxsBxLFdQnJxdfvybaQ+qt6bvShqg8Ijus4rveqFSO7NRamGX4KZmvIdgVQ1uMLT5PYuC2u6F+hLhCLg7XoqzqxGtl+4kIgGedQzxxsHzxa1D7x1Hx7SsTlb9xJKJRVE89P0/KOtnf root@192.168.1.40

將客戶端(jenkins)服務器的私鑰配置到jenkins管理界面裏,

git代碼倉庫拉代碼的pipeline腳本產生方法

下圖是上圖步驟3裏,點開後的配置

下圖是ssh-keygen產生的私鑰 .ssh/id_rsa

到此,步驟5裏,就產生了pipeline腳本,免交互方式讓jenkins服務器拉取git代碼倉庫裏的代碼

 

 

做者: 梅梅~

出處: https://www.cnblogs.com/keeptesting

關於做者:專一軟件測試,測試運維相關工做,請多多賜教!

本文版權歸做者和博客園共有,歡迎轉載,但未經做者贊成必須保留此段聲明,且在文章頁面明顯位置給出, 原文連接 歡迎溝通交流加微信聯繫。 微信:yangguangkg20140901 暗號:博客園.

相關文章
相關標籤/搜索