Step1:構建一個自由風格的php-deployphp
Step2:Gernal配置,丟棄舊的構建,防止jenkins構建較多以後變臃腫html
Step3:源碼管理:這裏使用git插件,也能夠使用svn插件java
將git路徑存在這裏還須要權限認證,不然會出現error 。
jenkins服務器上生成SSH-Keynode
[root@linux-node2 ~]# yum install -y git [root@linux-node2 ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Created directory '/root/.ssh'. 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:00FQjn5P6qAtok4BuE42TyfuNJnblzZ389XwKBhmHjY root@linux-node2 The key's randomart image is: +---[RSA 2048]----+ | .oo | |. + | |o . o | | o . . . | |.+.o . S E . . | |+ =.= B O +.| | ..B o + o ..o| | .o = .B + o .. | | .o+ o+.+ o o. | +----[SHA256]-----+ [root@linux-node2 ~]# cat .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+/XyUMNP5Wm63hhcACosVyRtmJxTSnT46HSKZ2PhduTHPIJcfhVTmeCk1zwO0fP8PmwXFf0+G9ki8CupE/+xcOy14TCqxNgvP8o514IjXOFV7SO1lnHKH3t0RfaFEloRZHnrgIcWiZrFvYRT/TFznWO86sfHPzlW6WF9elTqRURNR60bwv9C6iw4PpYjGVIST/SeGl75axtUjJr544jB5pEWtNZ09ktCKpPeFBvgCc9exdzOQuzaCXQrroNU0p6MB6KkoIOmpkN92cDPdg4EgBYDjwcl38FbXOq3N0QL8PT+IZpHBWFVEAZU2alI02H5NNUy9p2K/Br4NY3UvYZiP root@linux-node2
命令行測試添加ssh-key後可否正常拉取 [root@linux-node2 ~]# git clone git@192.168.56.11:java/app1.git Cloning into 'app1'... The authenticity of host '192.168.56.11 (192.168.56.11)' can't be established. ECDSA key fingerprint is SHA256:p2lhKmsPQ6K+dWHHvbJg0GV+Ni9VM7vlViKrYsZLP1s. ECDSA key fingerprint is MD5:22:14:1c:37:de:47:1c:4a:2f:88:b1:dc:e2:d0:02:17. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.56.11' (ECDSA) to the list of known hosts. remote: Counting objects: 11, done. remote: Compressing objects: 100% (7/7), done. remote: Total 11 (delta 0), reused 11 (delta 0) Receiving objects: 100% (11/11), done. [root@linux-node2 ~]# ll total 68048 -rw-------. 1 root root 948 Dec 3 01:26 anaconda-ks.cfg drwxr-xr-x 3 root root 62 Dec 21 15:53 app1 -rw-r--r-- 1 root root 69675984 Mar 2 2017 jenkins-2.32.3-1.1.noarch.rpm
而後保存,當即構建一次,會拉取master的代碼庫linux
點開能夠看到控制檯的輸出,如圖:git
/var/lib/jenkins/workspace/php-deploy目錄用於存放代碼信息 [root@linux-node2 php-deploy]# ll total 12 -rw-r--r-- 1 root root 28 Dec 21 16:11 index.html -rw-r--r-- 1 root root 12 Dec 21 16:11 new.html -rw-r--r-- 1 root root 19 Dec 21 16:11 readme [root@linux-node2 php-deploy]# pwd /var/lib/jenkins/workspace/php-deploy
這裏咱們拉取的代碼須要推送到遠程代碼目錄,須要以下操做:
架設linux-node1爲web服務,目錄爲/data/www/php-deploy web
[root@linux-node1 ~]# mkdir /data/www/php-deploy -p 添加node2的免祕鑰登錄 [root@linux-node1 ~]# vim .ssh/authorized_keys [root@linux-node1 ~]# chmod 600 .ssh/authorized_keys [root@linux-node2 ~]# ssh 192.168.56.11 Last login: Mon Dec 4 17:41:56 2017 from 192.168.56.1 [root@linux-node1 ~]#
修改項目設置,配置構建:Execute shell,至關於將代碼自動發佈到linux-node1的代碼目錄中。shell
接下來,咱們從新構建一次,並查看控制檯輸出:vim
在node1上查看目錄,也會有相應的代碼信息 服務器
[root@linux-node1 ~]# ll /data/www/php-deploy/ total 12 -rw-r--r-- 1 root root 28 Dec 21 16:11 index.html -rw-r--r-- 1 root root 12 Dec 21 16:11 new.html -rw-r--r-- 1 root root 19 Dec 21 16:11 readme [root@linux-node1 ~]#