一.jenkins的安裝配置
1.去官網下載war包,這種方式比較簡單方便
java -jar jenkins.war --httpPort=49001
2.首次運行有一個key放在服務器上需要你填入才能進入,同時需要配置賬號密碼
3.如果沒有被牆的話,最好把推薦的包都裝上
manage jenkin-》plugin manager-》git,mavne,publish over ssh 這三個插件裝上
因為整個流程最要就是用到這三個插件
git獲取代碼
maven自動構建
publish over ssh通過ssh傳送文件以及ssh去運行腳本
------------------------------------------------------------------
advanced里面
http proxy onfiguration 什么都不要填,填了就會出錯
如果被牆
uodate site 換成http://mirror.xmission.com/jenkins/updates/update-center.json
然后check now 看看行不行,之前是因為填了代理,所以一直不行
4 manage jenkin-》global tool configuration
jdk配本地的位置
maven和git就勾選自動安裝就可以,然后save
5 configure system
填上git pluging github的的相關
Publish over ssh
passphrase ssh時的密碼,
或者不填這個填ssh的key
然后填ssh server,username是登上去的ssh賬戶哦, remote directory是遠程主機可見的所有路徑
二 新建項目
jenkintest
里面有一個module叫做client,除了.idea,gitignore,pom.xml,其他全都可以刪掉。。idea只是為了維持目前的idea項目架構而已,git的時候也不需要
gitignore文件
### IntelliJ IDEA ### .idea *.iws *.iml *.ipr *mvnw *mvnw.cmd *HELP.md *.mvn
這樣就把所有模塊的都拿掉了
jenkin的pom.xml
1.打包方式用pom,默認不填的話是jar
<packaging>pom</packaging>
2. build的插件用maven而不是springboot
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <!--<encoding>${project.build.sourceEncoding}</encoding>--> </configuration> </plugin> </plugins> </build>
3. 模塊名寫上
<modules> <module>client</module> </modules>
<?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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.ljq</groupId> <artifactId>jenkintest</artifactId> <version>0.0.1-SNAPSHOT</version> <name>jenkinTest</name> <packaging>pom</packaging> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.SR1</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <modules> <module>client</module> </modules> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <!--<encoding>${project.build.sourceEncoding}</encoding>--> </configuration> </plugin> </plugins> </build> <!--<build>--> <!--<plugins>--> <!--<plugin>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-maven-plugin</artifactId>--> <!--</plugin>--> <!--</plugins>--> <!--</build>--> </project>
4.子模塊里的把parent從springboot換成父模塊即可,這樣就可以把所有的依賴都寫在父模塊的pom中,更加方便
<parent>
<groupId>com.ljq</groupId>
<artifactId>jenkintest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
5.這樣子之后mvn clean package是生成所有的子模塊的jar包,父模塊並不會生成
三 jenkin新建item
選擇maven project, 然后ok,然后就可以填寫configure
在第一次build之前沒有workspace,workspace是用來存git下來的文件並在本地進行構建,workspace也可以刪除
1 source code management
選擇git
填上倉庫地址
credentials -》 add jenkins 把 git的賬號密碼填上
credients就可以選擇了,那個name ref什么的不用填寫
2,。 build trigger
第一個選項是手動構建
第二個是利用url構建
Build periodically,定期構建
Poll SCM:定時檢查源碼變更(根據SCM軟件的版本號),如果有更新就checkout最新code下來,然后執行構建動作
3.定時構建語法
* * * * *
(五顆星,中間用空格隔開)
第一顆*表示分鍾,取值0~59
第二顆*表示小時,取值0~23
第三顆*表示一個月的第幾天,取值1~31
第四顆*表示第幾月,取值1~12
第五顆*表示一周中的第幾天,取值0~7,其中0和7代表的都是周日
1.每30分鍾構建一次:
H/30 * * * *
2.每2個小時構建一次
H H/2 * * *
3.每天早上8點構建一次
0 8 * * *
4.每天的8點,12點,22點,一天構建3次
0 8,12,22 * * *
(多個時間點,中間用逗號隔開)
4.build
跳過測試clean package -Dmaven.test.skip=True
5. 構建之后執行腳本
sourcefiles 就是你要傳送的jar包,可以去workspace看位置
remove prefix 把sourcefile的前綴去掉,只剩jar包名字
remote directory: jar復制到遠程機子上的位置