搭建 Jenkins-2.83 服務,部署 spring boot 專案
阿新 • • 發佈:2022-04-28
Jenkins 是什麼?
Jenkins 是一個可擴充套件的持續整合引擎。
主要用於:
持續、自動地構建/測試軟體專案。 監控一些定時執行的任務。
Jenkins 擁有的特性包括:
易於安裝-只要把jenkins.war
部署到servlet容器
,不需要資料庫支援。
易於配置-所有配置都是通過其提供的web介面實現。
整合RSS/E-mail通過RSS釋出構建結果或當構建完成時通過e-mail通知。
生成JUnit/TestNG測試報告。
分散式構建支援Jenkins能夠讓多臺計算機一起構建/測試。
檔案識別:Jenkins能夠跟蹤哪次構建生成哪些jar,哪次構建使用哪個版本的jar等。
外掛支援:支援擴充套件外掛,你可以開發適合自己團隊使用的工具。
準備工作
環境
JDK:1.8
Jenkins:2.83
Centos:7.3
安裝
下載
cd /opt
wget http://mirrors.jenkins.io/war/2.83/jenkins.war
啟動
關閉防護牆
systemctl stop firewalld.service
啟動服務
java -jar jenkins.war
Jenkins 就啟動成功了!它的war包自帶Jetty伺服器
訪問
瀏覽器訪問:http://localhost:8080/
第一次啟動Jenkins時,出於安全考慮,Jenkins會自動生成一個隨機的按照口令。
注意控制檯輸出的口令,複製下來,然後在瀏覽器輸入密碼:
************************************************************* Jenkins initial setup is required. An admin user has been created and a password generated. Please use the following password to proceed to installation: 84a2f219030f45568c89e6602af60877 This may also be found at: /root/.jenkins/secrets/initialAdminPassword *************************************************************
進入使用者自定義外掛介面,建議選擇安裝官方推薦外掛,因為安裝後自己也得安裝:
接下來是進入外掛安裝進度介面:
配置使用者名稱密碼:
初始化成功後進入 Jenkins 首頁:
全域性工具配置.Jdk,Mavem,git Docker,等配置,安裝
構建專案
新建專案
這裡,選擇構建一個自由風格的軟體專案;
原始碼管理
Jenkins支援多種原始碼管理伺服器;
構建配置
選擇 Execute shell
構建 輸入一下命令並且儲存
mvn clean package
立即構建
檢視日誌
Started by user ymq
Building in workspace /root/.jenkins/workspace/file-manager
Cloning the remote Git repository
Cloning repository https://github.com/souyunku/file-manager.git
> git init /root/.jenkins/workspace/file-manager # timeout=10
Fetching upstream changes from https://github.com/souyunku/file-manager.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/souyunku/file-manager.git +refs/heads/*:refs/remotes/origin/*
> git config remote.origin.url https://github.com/souyunku/file-manager.git # timeout=10
> git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
> git config remote.origin.url https://github.com/souyunku/file-manager.git # timeout=10
Fetching upstream changes from https://github.com/souyunku/file-manager.git
> git fetch --tags --progress https://github.com/souyunku/file-manager.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 3ef1aa74305bdfcbc5b79bb4d7b1eeaea62a959f (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 3ef1aa74305bdfcbc5b79bb4d7b1eeaea62a959f
Commit message: "*"
First time build. Skipping changelog.
[file-manager] $ /bin/sh -xe /tmp/jenkins3743583121531645127.sh
+ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building file-manager 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ file-manager ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ file-manager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 138 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ file-manager ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 29 source files to /root/.jenkins/workspace/file-manager/target/classes
[WARNING] /root/.jenkins/workspace/file-manager/src/main/java/io/ymq/fm/web/CloudStorageController.java: Some input files use unchecked or unsafe operations.
[WARNING] /root/.jenkins/workspace/file-manager/src/main/java/io/ymq/fm/web/CloudStorageController.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ file-manager ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/file-manager/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ file-manager ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ file-manager ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ file-manager ---
[INFO] Building jar: /root/.jenkins/workspace/file-manager/target/file-manager-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.654s
[INFO] Finished at: Tue Oct 10 14:23:39 CST 2017
[INFO] Final Memory: 25M/61M
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS
檢視 jar
部署專案
部署指令碼
把指令碼放到 /etc/rc.d/init.d
下賦許可權 chmod 777 spring-boot.sh
#!/bin/bash
SpringBoot=$2
if [ "$1" = "" ];
then
echo -e "