0推薦文章和網(wǎng)站
參考文章
使用Jenkins配置Git+Maven的自動化構(gòu)建
jenkins git插件安裝
Jenkins+Github持續(xù)集成
手動下載Jenkins插件網(wǎng)址
1持續(xù)集成的作用、過程和優(yōu)勢
- 持續(xù)集成就是快速、高頻率地自動構(gòu)建項目的所有源碼,并為項目成員提供豐富的反饋信息。
- 快速:集成速度要盡可能的塊,開發(fā)人員不希望自己提交的代碼提交半天后才得到反饋。
- 高頻率:頻率越高越好,例如每隔一個小時,這樣問題就可以盡早地反映出來。
- 自動*:持續(xù)集成應(yīng)該自動觸發(fā)并執(zhí)行的,不應(yīng)該有手工參與。
- 構(gòu)建:包括編譯、測試、審查、打包、部署等工作。
- 所有源碼:所有團隊成員提交到代碼庫里的最新的源代碼。
- 反饋:持續(xù)集成應(yīng)該通過各種快捷的方式告訴團隊最新的集成狀態(tài),當(dāng)集成失敗,反饋報告應(yīng)該盡可能地反映失敗的具體細(xì)節(jié)。
1.1典型應(yīng)用場景
開發(fā)人員對代碼做了一些修改,在本地運行構(gòu)建并確認(rèn)無誤之后,將更改提交到代碼庫(git、svn等)。具有高配置硬件的持續(xù)集成服務(wù)器每隔30分鐘查詢代碼庫一次,發(fā)現(xiàn)更新之后,簽出所有最新的源代碼,然后調(diào)用自動化構(gòu)建工具(maven、ant等)構(gòu)建項目,該過程包括編譯、測試、審查、打包和部署等。然而不幸的是,另外一名開發(fā)人員在這一時間段也提交了代碼更改,兩處更改導(dǎo)致了某些測試的失敗,持續(xù)集成服務(wù)器基于這些失敗的測試創(chuàng)建一個報告,并自動發(fā)送給相關(guān)開發(fā)人員。開發(fā)人員收到報告后,立即著手調(diào)查選用,并盡快修復(fù)。

2Jenkins簡介
Jenkins是一款持續(xù)集成工具,它的前身是Hudson。使用jenkins還不能夠完成持續(xù)集成工作,還需要版本控制工具(git、svn等)和項目構(gòu)建工具(maven、ant等)配合才可以完成。
3.準(zhǔn)備
- 首先需要理解的是,Jenkins是幫我們將代碼進行統(tǒng)一的編譯打包、還可以放到tomcat容器中進行發(fā)布。
- 意思是我們通過配置,將以前:編譯、打包、上傳、部署到Tomcat中的過程交由Jenkins,Jenkins通過給定的代碼地址URL,將代碼拉取到其“宿主服務(wù)器”(這是我個人的稱呼,在下邊會用到,就是Jenkins的安裝位置),進行編譯、打包和發(fā)布到容器中。
- 因此我們可以注意到的是,在Jenkins的宿主服務(wù)器中必須要有可以進行:代碼clone(Git)、代碼編譯(Maven)、代碼運行(Tomcat)的基本環(huán)境,其他文章上來就是安裝jenkins,忽略了一些基本的配置。
- 下面我寫的案例是一個普通的java項目,涉及到的軟件有g(shù)it、maven、nexus、tomcat、jekins。所以需要確保已經(jīng)安裝。關(guān)于git的安裝上面文章有介紹,關(guān)于maven,nexus的安裝我前面文章有介紹。
3.1安裝jenkins
jenkins是一個war文件,下載jenkins,我下載的是2.19.4版本
運行前先配置jenkins的工作目錄,jenkins的工作目錄會隨著任務(wù)的變多而占用磁盤空間變大,所以在此之前可以配置一下工作目錄。請看maven---12Jenkins工作目錄
下載后可以通過 java -jar jenkins.war --httpPort=8080直接運行(其內(nèi)置了jetty服務(wù)器),或者直接放到tomcat的webapps目錄下了,再啟動tomcat。下面以tomcat方式運行。然后訪問http://localhost:8080/jenkins 就進入jenkins管理界面了。
第一次進入網(wǎng)站,jenkins會生成jenkins的工作目錄,然后讓你輸入管理員密碼進入,該密碼你根據(jù)提示信息去工作目錄中就可以找到。密碼會存在jenkins的工作目錄中的secrets\initialAdminPass文件中。E:\soft\jenkins\jenkins_work\secrets\initialAdminPassword
-
密碼輸入后進入安裝插件界面,點擊推薦安裝,如果此時出現(xiàn)如下界面,則嘗試重啟jenkins,重啟tomcat,一般情況的重啟方法是在瀏覽器輸入http://localhost:8080/restart,但是這種情況還是重啟tomcat 。
Paste_Image.png 如果jenkins一直在啟動狀態(tài)有可能內(nèi)存溢出了,為你的tomcat的虛擬機設(shè)置大一點運行內(nèi)存。

4配置插件
- 進入jenkins會讓你下載一些必要的插件和推薦的插件,需要安裝某些插件才可以使用一些工具,比如jenkins默認(rèn)不支持git,所以要下載git相關(guān)插件才可以讓jenkins支持。而網(wǎng)絡(luò)原因有可能會下載失敗,所以還需要手動下載。


- 插件安裝失敗如果沒有進入主界面執(zhí)行http://localhost:8080/restart 重啟后。進入后就是手動下載需要的插件了,包括下載失敗的插件都需要手動下載,在配置上來。
- 有些插件的安裝需要依賴其他插件,所以如果某一個插件安裝失敗會影響到其它插件的安裝。
- 對于插件的精確選擇,我還不是太明白,只是知道需要git、github、maven,在下的時候因為插件間依賴原因也多下了其它的。
- 插件的參考來自于上面兩篇文章。
4.1確定需要下載的插件
- 大概確定要下插件我的這個jenkins版本內(nèi)置了maven插件,所以主要下載git、github和jenkins推薦的必要插件,最終我因為還不是太懂好像也下了一些用不到的插件,我一開始也沒有下那么多,但是在建任務(wù)時發(fā)現(xiàn)有些配置沒有,所以又去[插件管理]中尋找相關(guān)插件。
4.2聯(lián)網(wǎng)下載的插件
- 第一次登陸http://localhost:8080/jenkins 網(wǎng)站會讓你下載相關(guān)插件,我選了上面的幾個插件。然后會進入下載等待,最后會給你提示下載的成功情況,有的插件下載失敗有的成功了。
4.3手動下載插件
在Jenkins一開始會讓你選擇安裝插件,但是由于網(wǎng)絡(luò)原因會下載失敗,有的插件安裝失敗,所以需要手動下載在上傳上傳。
4.3.1尋找需要下載的插件
有的插件安裝失敗,進入管理界面就會出現(xiàn)如下錯誤:

案例:上面錯誤有兩個(這是我解決了部分后還剩下的),先解決pipeline:Stage View plugin v2.4插件安裝失敗。根據(jù)提示發(fā)現(xiàn)失敗原因是需要先安裝pipeline-rest-api v2.4插件。
根據(jù)錯誤提示去插件網(wǎng)站搜索(Ctr+f)需要下載的pipeline-rest-api v2.4插件。
4.3.2下載需要的插件


下載的是一個一.hpi結(jié)尾的文件。
4.3.3上傳插件
系統(tǒng)管理–管理插件–高級Tab->上傳插件
-
上傳插件
Paste_Image.png -
查看安裝狀態(tài)
安裝成功

4.4重啟jekins
有的插件安裝完成需要重啟才能生效(會有提示),重啟就是重啟tomcat就可以。重啟完后已安裝的插件就不會出現(xiàn)錯誤提示了。

5配置jenkins全局工具

6新建一個任務(wù)
6.1.1任務(wù)需求
- 通過持續(xù)集成不斷的把一個java項目的最新構(gòu)件自動發(fā)布到nexus倉庫中,其中會通過反饋機制返回集成的狀態(tài)和錯誤報告。(但是反饋好像沒起作用,有可能是郵箱配錯了,猜測)
- 源碼管理:github,項目構(gòu)建工具maven,項目生成構(gòu)件發(fā)布到nexus上。
-
在jenkins中新建一個自由風(fēng)格項目,自由風(fēng)格項目不僅支持maven項目還支持其他類型項目。
Paste_Image.png
6.1.2任務(wù)配置(寫的不是太詳細(xì)后面在補充)
6.1.2.1概念解釋
- 任務(wù)需要配置舊構(gòu)建丟棄策略、源碼管理、構(gòu)建觸發(fā)器、構(gòu)建、構(gòu)建后操作。
-
丟棄策略:
下圖是hudson的丟棄策略同樣適用于jenkins,因為hudson是jenkins前身。
丟棄策略 - 源碼管理:
項目源碼管理我選擇的是git源碼管理工具,所以我已經(jīng)在github上創(chuàng)建了一個cidemo倉庫。配置它的時候除了配置項目地址,還要配置git在本機的認(rèn)證信息,該處參考了上面兩篇文章。 - 構(gòu)建觸發(fā)器:


-
構(gòu)建
讓jenkins選擇用什么命令構(gòu)建項目,在前面我們配置maven所以會選擇[invoke top-level Maven targets]進行配置。
Paste_Image.png 構(gòu)建后操作
該步驟配置構(gòu)建完后的一些任務(wù),有哪些可以在這里配置呢?任務(wù)測試報告,郵件反饋等。
其中郵件反饋最重要,下一篇文件介紹maven---11配置jenkins的郵件反饋。
6.1.2.2建一個helloword任務(wù)



-
上面觸發(fā)條件的Poll SCM說明有誤,應(yīng)該是固定時間去輪詢源碼庫,發(fā)現(xiàn)有更新的時候才構(gòu)建本項目
配置生成測試報告
6.1.3jenkins中的已建好的任務(wù)

- 在jenkins首頁顯示所有任務(wù)。
描述任務(wù)有幾個屬性,其中: - 第一列狀態(tài)(S):任務(wù)狀態(tài),使用顏色表示任務(wù)當(dāng)前狀態(tài)。
- 藍色:任務(wù)最近一次的構(gòu)建是成功的。
- 紅色:任務(wù)最近一次的構(gòu)建是失敗的。
- 黃色:任務(wù)最近一次的構(gòu)建是成功的,但是不穩(wěn)定(主要因為有失敗的測試)。
- 灰色:任務(wù)從未被執(zhí)行過或者被禁用。
- 圖標(biāo)閃爍:任務(wù)正在執(zhí)行一次構(gòu)建
- 第二列天氣(W):使用天氣表示任務(wù)長期的一個狀態(tài)


- 任務(wù)不夠健康時要盡快采取修復(fù)措施。
- 其它屬性看一下就明白了。
- 點擊項目名稱就可以進入項目查看項目的一些構(gòu)建情況。

- 菜單里的工作空間就是源碼庫管理的項目本下載在本地的位置,里面可以看到項目源碼。
6.2編寫項目并上傳到github上
6.2.1 clone項目導(dǎo)本地
- 首先克隆github上項目cidemo到本地。
git clone https://github.com/zlcook/cidemo.git
6.2.2編寫代碼
- 我直接把maven---3手寫一個helloWord中的maven項目內(nèi)容拷貝到該目錄下。(這個項目還不能滿足任務(wù)的要求下面會跟隨問題一步一步完善)。
- 項目包含的內(nèi)容
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zlcook.studymvn</groupId>
<artifactId>helloword</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>maven helloword project</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--配置插件將main方法的類信息添加到manifest中,從而可以通過命令[java -jar 架包.jar]來執(zhí)行生成的jar包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.zlcook.studymvn.helloword.HelloWord</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- 主代碼:src\main\java\com\zlcook\studymvn\helloword\HelloWord.java
package com.zlcook.studymvn.helloword;
public class HelloWord
{
public String say(){
return "hello maven";
}
public static void main(String[] args){
System.out.print(new HelloWord().say());
}
}
- 測試代碼:src\test\java\com\zlcook\studymvn\helloword\HelloWordTest.java
package com.zlcook.studymvn.helloword;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HelloWordTest
{
@Test
public void testSay(){
HelloWord helloWord = new HelloWord();
String result = helloWord.say();
assertEquals("hello maven",result);
}
}

6.2.3提交到github上
在cidemo目錄下進行如下操作
查看變動文件
git status添加所有文件到緩存中
git add .提交文件到本地倉庫
git commit -m "第一次提交"提交到github上的master分支
git push origin HEAD:master填寫github的用戶名和密碼

- 完成
6.3構(gòu)建項目
- 在jenkins的helloword任務(wù)(任務(wù)名稱和github上的倉庫名稱取得不一致,當(dāng)然一致最好)執(zhí)行“立即構(gòu)建”。
6.3.1第一次構(gòu)建
6.3.1.1構(gòu)建結(jié)果失敗
Started by user zlcook
Building in workspace C:\Windows\system32\config\systemprofile\.jenkins\workspace\helloword
> D:\Soft\git\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> D:\Soft\git\Git\bin\git.exe config remote.origin.url https://github.com/zlcook/cidemo.git # timeout=10
Fetching upstream changes from https://github.com/zlcook/cidemo.git
> D:\Soft\git\Git\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials
> D:\Soft\git\Git\bin\git.exe fetch --tags --progress https://github.com/zlcook/cidemo.git +refs/heads/*:refs/remotes/origin/*
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision e75623ce6b045f7db3667c1dccfb3e3cc61e21c7 (refs/remotes/origin/master)
> D:\Soft\git\Git\bin\git.exe config core.sparsecheckout # timeout=10
> D:\Soft\git\Git\bin\git.exe checkout -f e75623ce6b045f7db3667c1dccfb3e3cc61e21c7
> D:\Soft\git\Git\bin\git.exe rev-list e75623ce6b045f7db3667c1dccfb3e3cc61e21c7 # timeout=10
[helloword] $ cmd.exe /C "D:\Soft\maven\apache-maven-3.3.3\bin\mvn.cmd -s D:\Soft\maven\apache-maven-3.3.3\conf\settings.xml clean deploy && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven helloword project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.maven.plugins:maven-resources-plugin:jar:2.6 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.109 s
[INFO] Finished at: 2016-11-30T15:07:16+08:00
[INFO] Final Memory: 5M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failure to find org.apache.maven.plugins:maven-resources-plugin:jar:2.6 in http://172.19.201.155:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
6.3.1.2第一次失敗原因及解決方法
- 失敗原因部署私服的服務(wù)器沒有網(wǎng),本地緩存了錯誤,解決方法刪掉本地的maven-resources-plugin插件,讓私服連接上網(wǎng)絡(luò)。
詳細(xì)一點的原因分析maven---9使用Nexus創(chuàng)建私服--->3.4.2代理倉庫配置信息下面的案例。
6.3.2第二次構(gòu)建
6.3.2.1構(gòu)建結(jié)果失敗
Started by user zlcook
Building in workspace C:\Windows\system32\config\systemprofile\.jenkins\workspace\helloword
> D:\Soft\git\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> D:\Soft\git\Git\bin\git.exe config remote.origin.url https://github.com/zlcook/cidemo.git # timeout=10
Fetching upstream changes from https://github.com/zlcook/cidemo.git
> D:\Soft\git\Git\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials
> D:\Soft\git\Git\bin\git.exe fetch --tags --progress https://github.com/zlcook/cidemo.git +refs/heads/*:refs/remotes/origin/*
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision e75623ce6b045f7db3667c1dccfb3e3cc61e21c7 (refs/remotes/origin/master)
> D:\Soft\git\Git\bin\git.exe config core.sparsecheckout # timeout=10
> D:\Soft\git\Git\bin\git.exe checkout -f e75623ce6b045f7db3667c1dccfb3e3cc61e21c7
> D:\Soft\git\Git\bin\git.exe rev-list e75623ce6b045f7db3667c1dccfb3e3cc61e21c7 # timeout=10
[helloword] $ cmd.exe /C "D:\Soft\maven\apache-maven-3.3.3\bin\mvn.cmd -s D:\Soft\maven\apache-maven-3.3.3\conf\settings.xml clean deploy && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven helloword project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
2/8 KB
6/8 KB
8/8 KB
Downloaded: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom (8 KB at 2.9 KB/sec)
Downloading: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar
2/29 KB
6/29 KB
10/29 KB
14/29 KB
18/29 KB
22/29 KB
26/29 KB
29/29 KB
Downloaded: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.jar (29 KB at 18.0 KB/sec)
Downloading: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom
Downloaded: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom (0 B at 0.0 KB/sec)
Downloading: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-plugins/24/maven-plugins-24.pom
Downloaded: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-plugins/24/maven-plugins-24.pom (0 B at 0.0 KB/sec)
Downloading: http://172.19.201.155:8081/repository/maven-public/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.jar
....省略下載各種構(gòu)件
Downloaded: http://172.19.201.155:8081/repository/maven-public/org/codehaus/plexus/plexus-utils/3.0.22/plexus-utils-3.0.22.jar (0 B at 0.0 KB/sec)
Downloaded: http://172.19.201.155:8081/repository/maven-public/com/google/guava/guava/11.0.2/guava-11.0.2.jar (0 B at 0.0 KB/sec)
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT.jar with C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT-shaded.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ helloword ---
[INFO] Installing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT.jar to D:\Soft\maven\maven_jar\repository\com\zlcook\studymvn\helloword\0.0.1-SNAPSHOT\helloword-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\pom.xml to D:\Soft\maven\maven_jar\repository\com\zlcook\studymvn\helloword\0.0.1-SNAPSHOT\helloword-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ helloword ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:11 min
[INFO] Finished at: 2016-11-30T15:17:39+08:00
[INFO] Final Memory: 19M/159M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project helloword: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
6.3.2.2第二次失敗原因分析及解決辦法
- 小發(fā)現(xiàn):首先我們發(fā)現(xiàn)本地maven去nexus私服上檢查構(gòu)件更新時發(fā)現(xiàn)maven-resources-plugin沒有(上一步刪掉了),然后進行下載,后面對于其他的構(gòu)件進行檢查發(fā)現(xiàn)沒有更新所以都沒有下載(0 B at 0.0 KB/sec)。
-
a.分析原因:
沒有為項目配置構(gòu)件發(fā)布的位置。
Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project helloword: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
-
b.配置發(fā)布到nexus私服上
下面是在項目的pom中添加生成構(gòu)件發(fā)布的位置,當(dāng)然如果私服需要認(rèn)證信息,需要在settings.xml文件的services中配置他們的認(rèn)證信息。案例請看maven---9使用Nexus創(chuàng)建私服---->5.2部署Maven項目構(gòu)件至Nexus。
<?xml version="1.0" encoding="UTF-8"?>
<project>
...
<!--設(shè)置項目統(tǒng)一構(gòu)件文件的編碼-->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<!--配置項目生成的構(gòu)件部署到Nexus私服上 -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus ReleaseRepository</name>
<url>http://172.19.201.155:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus SnapshotsRepository</name>
<url>http://172.19.201.155:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
c.提交代碼到github上
修改了代碼則需要將變動信息提交到github上,操作步驟參考上面。
d.再次構(gòu)建任務(wù)成功
因為配置任務(wù)的時候配置了【每隔15分鐘輪詢源碼庫,如果發(fā)現(xiàn)有更新的時候構(gòu)建本項目】和【發(fā)現(xiàn)github上有變化時構(gòu)建本項目】,所以我這次沒有手動構(gòu)建,讓jenkins通過構(gòu)建觸發(fā)器來自動構(gòu)建項目。
構(gòu)建成功后任務(wù)的console輸出
Started by an SCM change
Building in workspace C:\Windows\system32\config\systemprofile\.jenkins\workspace\helloword
> D:\Soft\git\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> D:\Soft\git\Git\bin\git.exe config remote.origin.url https://github.com/zlcook/cidemo.git # timeout=10
Fetching upstream changes from https://github.com/zlcook/cidemo.git
> D:\Soft\git\Git\bin\git.exe --version # timeout=10
using GIT_SSH to set credentials
> D:\Soft\git\Git\bin\git.exe fetch --tags --progress https://github.com/zlcook/cidemo.git +refs/heads/*:refs/remotes/origin/*
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> D:\Soft\git\Git\bin\git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision ae2a6a18ebfd933e4fa81c3f7f691d8fb870a240 (refs/remotes/origin/master)
> D:\Soft\git\Git\bin\git.exe config core.sparsecheckout # timeout=10
> D:\Soft\git\Git\bin\git.exe checkout -f ae2a6a18ebfd933e4fa81c3f7f691d8fb870a240
> D:\Soft\git\Git\bin\git.exe rev-list 15e935f15d8ac3190d7423eb5132b2e847a518ee # timeout=10
[helloword] $ cmd.exe /C "D:\Soft\maven\apache-maven-3.3.3\bin\mvn.cmd -s D:\Soft\maven\apache-maven-3.3.3\conf\settings.xml clean deploy && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven helloword project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ helloword ---
[INFO] Deleting C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ helloword ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ helloword ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ helloword ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ helloword ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ helloword ---
[INFO] Surefire report directory: C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.zlcook.studymvn.helloword.HelloWordTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.038 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ helloword ---
[INFO] Building jar: C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:2.4.3:shade (default) @ helloword ---
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT.jar with C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT-shaded.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ helloword ---
[INFO] Installing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\target\helloword-0.0.1-SNAPSHOT.jar to D:\Soft\maven\maven_jar\repository\com\zlcook\studymvn\helloword\0.0.1-SNAPSHOT\helloword-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Windows\System32\config\systemprofile\.jenkins\workspace\helloword\pom.xml to D:\Soft\maven\maven_jar\repository\com\zlcook\studymvn\helloword\0.0.1-SNAPSHOT\helloword-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ helloword ---
Downloading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/maven-metadata.xml
778/778 B
Downloaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/maven-metadata.xml (778 B at 2.4 KB/sec)
Uploading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/helloword-0.0.1-20161201.015626-2.jar
2/4 KB
4/4 KB
Uploaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/helloword-0.0.1-20161201.015626-2.jar (4 KB at 28.1 KB/sec)
Uploading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/helloword-0.0.1-20161201.015626-2.pom
2/3 KB
3/3 KB
Uploaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/helloword-0.0.1-20161201.015626-2.pom (3 KB at 21.7 KB/sec)
Downloading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/maven-metadata.xml
288/288 B
Downloaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/maven-metadata.xml (288 B at 5.6 KB/sec)
Uploading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/maven-metadata.xml
778/778 B
Uploaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/0.0.1-SNAPSHOT/maven-metadata.xml (778 B at 7.4 KB/sec)
Uploading: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/maven-metadata.xml
288/288 B
Uploaded: http://172.19.201.155:8081/repository/maven-snapshots/com/zlcook/studymvn/helloword/maven-metadata.xml (288 B at 2.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.865 s
[INFO] Finished at: 2016-12-01T09:56:27+08:00
[INFO] Final Memory: 20M/198M
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS
下一個demo
cidemo項目不是一個javaEE項目,目前沒有涉及到tomcat,后面會做一個javaEE項目,通過持續(xù)集成把項目自動部署到tomcat上。當(dāng)然在這之前我要學(xué)會編寫shell腳本。
總結(jié)
這篇文章沒有寫持續(xù)集成的郵件反饋,一個項目在持續(xù)集成過程中如果出錯了,這個錯誤信息要及時反饋給項目經(jīng)理及造成這次錯誤的開發(fā)人員,以便盡快修復(fù)。下一篇文章我會介紹maven---11配置jenkins的郵件反饋
留言
有什么不懂的一起探討一下吧,歡迎留下寶貴意見,喜歡就點個贊吧(哈哈),多謝鼓勵。






