continuous integration (CI),持續集成是一種軟件開發實踐,即團隊開發成員常常集成他們的工做,一般每一個成員,天天至少集成一次,也就意味着天天可能會發生屢次集成。每次集成都經過自動化構建(包括編譯、發佈、自動化測試)來驗證,從而儘快的發現集成錯誤。許多團隊發現這個過程能夠大大減小集成的問題,讓團隊可以更快的開發內聚的軟件。
php
Jenkins is an automation engine with an unparalleled plugin ecosystem to support all of your favorite tools in your delivery pipelines,wether your goal is continuous integration,automated testing,or continuous delivery.
java
Jenkins 是持續集成、自動測試、持續部署的超級引擎,支持自定義工具集、多種交付通道。
node
1 #安裝依賴 2 [root@linux-node2 ~]# yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel 3 #下載Jenkins包 4 [root@linux-node2 src]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.32.3-1.1.noarch.rpm 5 #rpm安裝 6 [root@linux-node2 src]# rpm -ivh jenkins-2.32.3-1.1.noarch.rpm 7 #啓動Jenkins 8 [root@linux-node2 src]# systemctl start jenkins 9 #查看端口是否啓動 10 [root@linux-node2 src]# netstat -lntup
tcp6 0 0 :::8080 :::* LISTEN 17737/java
打開瀏覽器:http://192.168.56.12:8080linux
輸入密碼:git
1 #查看頁面上提供的該文件內容(默認密碼) 2 [root@linux-node2 src]# cat /var/lib/jenkins/secrets/initialAdminPassword 3 8afe5fe9dd7a48e0a1817b287b627dfc
選擇安裝默認插件或者直接關閉web
看到以上界面,Jenkins就已成功安裝apache
1 #將插件移動到指定目錄下 2 [root@linux-node2 src]# mv plugins.tar.gz /var/lib/jenkins/ 3 #進入指定目錄 4 [root@linux-node2 src]# cd /var/lib/jenkins/ 5 #解壓插件 6 [root@linux-node2 jenkins]# tar xf plugins.tar.gz
7 #受權
8 [root@linux-node2 jenkins]# chown -R jenkins.jenkins plugins 9 #重啓服務 10 [root@linux-node2 plugins]# systemctl restart jenkins
1 #編輯配置文件 2 [root@linux-node2 jenkins]# vim /etc/sysconfig/jenkins 3 #生產中建議使用Jenkins 4 29 JENKINS_USER="root"
/var/lib/jenkins 主目錄vim
/etc/init.d/jenkins 啓動文件瀏覽器
/var/cache/jenkins/ 程序文件jvm
/var/log/jenkins/ 日誌文件
丟棄舊的構建:保存10天的
找到GIT的項目URL(隨便選的)
進項目界面,再點擊 deploy keys
將那個KEY,enable一下
1 #在另外一臺機器上建立一個放代碼的目錄 2 [root@linux-node1 ~]# mkdir -p /data/www/php-deploy
點擊當即構建
1 #查看構建後的代碼 2 [root@linux-node2 php-deploy]# ll 3 total 4 4 -rw-r--r-- 1 root root 16 May 14 01:48 README.md 5 #查看Jenkins拉代碼的目錄 6 [root@linux-node2 php-deploy]# pwd 7 /var/lib/jenkins/workspace/php-deploy 8 #查看構建後是否同步成功 9 [root@linux-node1 ~]# ll /data/www/php-deploy/ 10 total 4 11 -rw-r--r-- 1 root root 16 May 14 2017 README.md
至此,PHP項目就已成功發佈。
往gitlab上,上傳一個maven項目:
1 #進入項目目錄 2 [root@linux-node1 ~]# cd java2 3 #初始化成git倉庫 4 [root@linux-node1 java2]# git init 5 Initialized empty Git repository in /root/java2/.git/ 6 #添加 7 [root@linux-node1 java2]# git add . 8 #提交 9 [root@linux-node1 java2]# git commit -m "first commit" 10 [master (root-commit) 3bad291] first commit 11 3 files changed, 100 insertions(+) 12 create mode 100644 pom.xml 13 create mode 100644 src/main/java/com/ghz/testweb/App.java 14 create mode 100644 src/test/java/com/ghz/testweb/AppTest.java 15 #遠程倉庫 16 [root@linux-node1 java2]# git remote add origin git@192.168.56.11:root/java-maven.git 17 #上傳 18 [root@linux-node1 java2]# git push origin master
1 #手動安裝maven 2 [root@linux-node2 ~]# tar xf apache-maven-3.3.9-bin.tar.gz 3 #放到/usr/local下 4 [root@linux-node2 ~]# mv apache-maven-3.3.9 /usr/local/ 5 #設置環境變量 6 [root@linux-node2 bin]# export PATH="$PATH:/usr/local/apache-maven-3.3.9/bin" 7 #添加到環境變量文件 8 [root@linux-node2 bin]# echo 'export PATH="$PATH:/usr/local/apache-maven-3.3.9/bin"' >> /etc/profile 9 #查看mvn版本 10 [root@linux-node2 bin]# mvn -v 11 Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) 12 Maven home: /usr/local/apache-maven-3.3.9 13 Java version: 1.8.0_131, vendor: Oracle Corporation 14 Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-2.b11.el7_3.x86_64/jre 15 Default locale: en_US, platform encoding: UTF-8 16 OS name: "linux", version: "3.10.0-327.36.3.el7.x86_64", arch: "amd64", family: "unix"
17 #修改鏡像
18 [root@linux-node2 bin]# vim /usr/local/apache-maven-3.3.9/conf/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>faxuan</id>
<mirrorOf>*</mirrorOf>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>default</id>
<repositories>
<repository>
<id>public</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>default</activeProfile>
</activeProfiles>
</settings
1 #查看構建結果 2 [root@linux-node2 target]# pwd 3 /var/lib/jenkins/workspace/java-maven/target 4 [root@linux-node2 target]# ll 5 total 8 6 drwxr-xr-x 3 root root 16 May 14 04:36 classes 7 drwxr-xr-x 2 root root 27 May 14 04:36 maven-archiver 8 drwxr-xr-x 3 root root 34 May 14 04:36 maven-status 9 -rw-r--r-- 1 root root 2431 May 14 04:36 original-testweb-v1.4.jar 10 drwxr-xr-x 2 root root 79 May 14 04:36 surefire-reports 11 drwxr-xr-x 3 root root 16 May 14 04:36 test-classes 12 -rw-r--r-- 1 root root 2658 May 14 04:36 testweb-v1.4.jar
【開源是一種精神,分享是一種美德】
— By GoodCook
— 筆者QQ:253097001
— 歡迎你們隨時來交流
—原創做品,容許轉載,轉載時請務必以超連接形式標明文章 原始出處 、做者信息和本聲明。不然將追究法律責任。