需要先搭建java環(huán)境:jdk、maven、git、docker
參考文檔:java環(huán)境安裝
官網(wǎng)地址
官網(wǎng)中有LTS和每周發(fā)布的兩個版本,盡量選擇LTS版本,LTS版本下方可看到以前的發(fā)行版,最新版本的需要java11以及以上
[root@localhost jenkins]# wget --no-check-certificate https://mirrors.jenkins.io/war-stable/2.346.1/jenkins.war
3. 啟動jenkins[root@localhost jenkins]# nohup java -jar /usr/local/jenkins/jenkins.war >/usr/local/jenkins/jenkins.out &
4. 查看啟動日志啟動成功并初始化管理員密碼在日志中:419dfb18c7d4486cbf00907d52689aaa
[root@localhost local]# tail -100f jenkins/jenkins.out
十二月 09, 2022 2:40:10 下午 Main verifyJavaVersion
警告: You are running Jenkins on Java 1.8, support for which will end on or after September 1, 2022. Please refer to the documentation for details on upgrading to Java 11: https://www.jenkins.io/redirect/upgrading-jenkins-java-version-8-to-11
Running from: /usr/local/jenkins/jenkins.war
webroot: $user.home/.jenkins
2022-12-09 06:40:12.899+0000 [id=1] INFO org.eclipse.jetty.util.log.Log#initialized: Logging initialized @2960ms to org.eclipse.jetty.util.log.JavaUtilLog
2022-12-09 06:40:13.212+0000 [id=1] INFO winstone.Logger#logInternal: Beginning extraction from war file
2022-12-09 06:40:20.879+0000 [id=1] WARNING o.e.j.s.handler.ContextHandler#setContextPath: Empty contextPath
2022-12-09 06:40:21.342+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: jetty-9.4.45.v20220203; built: 2022-02-03T09:14:34.105Z; git: 4a0c91c0be53805e3fcffdcdcc9587d5301863db; jvm 1.8.0_291-b10
2022-12-09 06:40:23.761+0000 [id=1] INFO o.e.j.w.StandardDescriptorProcessor#visitServlet: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
2022-12-09 06:40:23.920+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: DefaultSessionIdManager workerName=node0
2022-12-09 06:40:23.920+0000 [id=1] INFO o.e.j.s.s.DefaultSessionIdManager#doStart: No SessionScavenger set, using defaults
2022-12-09 06:40:23.922+0000 [id=1] INFO o.e.j.server.session.HouseKeeper#startScavenging: node0 Scavenging every 600000ms
2022-12-09 06:40:32.510+0000 [id=1] INFO hudson.WebAppMain#contextInitialized: Jenkins home directory: /root/.jenkins found at: $user.home/.jenkins
2022-12-09 06:40:33.776+0000 [id=1] INFO o.e.j.s.handler.ContextHandler#doStart: Started w.@21362712{Jenkins v2.346.1,/,file:///root/.jenkins/war/,AVAILABLE}{/root/.jenkins/war}
2022-12-09 06:40:34.865+0000 [id=1] INFO o.e.j.server.AbstractConnector#doStart: Started ServerConnector@79e4c792{HTTP/1.1, (http/1.1)}{0.0.0.0:8080}
2022-12-09 06:40:34.865+0000 [id=1] INFO org.eclipse.jetty.server.Server#doStart: Started @24928ms
2022-12-09 06:40:34.866+0000 [id=22] INFO winstone.Logger#logInternal: Winstone Servlet Engine running: controlPort=disabled
2022-12-09 06:40:37.154+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Started initialization
2022-12-09 06:40:37.173+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: Listed all plugins
2022-12-09 06:41:23.904+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: Prepared all plugins
2022-12-09 06:41:24.205+0000 [id=34] INFO jenkins.InitReactorRunner$1#onAttained: Started all plugins
2022-12-09 06:41:24.244+0000 [id=27] INFO jenkins.InitReactorRunner$1#onAttained: Augmented all extensions
2022-12-09 06:41:26.136+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: System config loaded
2022-12-09 06:41:26.137+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: System config adapted
2022-12-09 06:41:26.137+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Loaded all jobs
2022-12-09 06:41:26.141+0000 [id=28] INFO jenkins.InitReactorRunner$1#onAttained: Configuration for all jobs updated
2022-12-09 06:41:26.283+0000 [id=48] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Started Download metadata
2022-12-09 06:41:26.373+0000 [id=48] INFO hudson.util.Retrier#start: Attempt #1 to do the action check updates server
2022-12-09 06:41:28.276+0000 [id=29] INFO jenkins.install.SetupWizard#init:
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
419dfb18c7d4486cbf00907d52689aaa
This may also be found at: /root/.jenkins/secrets/initialAdminPassword
*************************************************************
*************************************************************
*************************************************************
2022-12-09 06:43:31.057+0000 [id=29] INFO jenkins.InitReactorRunner$1#onAttained: Completed initialization
2022-12-09 06:43:31.888+0000 [id=21] INFO hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up and running
2022-12-09 06:43:39.659+0000 [id=48] INFO h.m.DownloadService$Downloadable#load: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
2022-12-09 06:43:39.660+0000 [id=48] INFO hudson.util.Retrier#start: Performed the action check updates server successfully at the attempt #1
2022-12-09 06:43:39.672+0000 [id=48] INFO hudson.model.AsyncPeriodicWork#lambda$doRun$1: Finished Download metadata. 133,383 ms
5. 訪問jenkinshttp://+ip+8080 (可以配置域名訪問,我這里配置的域名訪問,用ip+端口也可以訪問)
啟動成功需要輸入初始化密碼,輸入后選擇安裝推薦插件
此處的密碼即為第四步中的密碼
[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-jzHpfMIC-1672024910306)(https://finger-guitar.oss-cn-hangzhou.aliyuncs.com/jenkins/2.png)]
此處需要配置國內(nèi)鏡像
官方下載插件慢 更新下載地址
cd {你的Jenkins工作目錄}/updates #進入更新配置位置
sed -i ‘s/http://updates.jenkins-ci.org/download/https://mirrors.tuna.tsinghua.edu.cn/jenkins/g’ default.json && sed -i ‘s/http://www.google.com/https://www.baidu.com/g’ default.json
[root@localhost updates]# cd /root/.jenkins/updates/
[root@localhost updates]# ll
總用量 2992
-rw-r--r--. 1 root root 2723189 12月 9 14:43 default.json
-rw-r--r--. 1 root root 40867 12月 9 15:06 hudson.plugins.gradle.GradleInstaller
-rw-r--r--. 1 root root 5569 12月 9 15:06 hudson.tasks.Ant.AntInstaller
-rw-r--r--. 1 root root 6178 12月 9 14:43 hudson.tasks.Maven.MavenInstaller
-rw-r--r--. 1 root root 279724 12月 9 15:06 hudson.tools.JDKInstaller
[root@localhost updates]#
[root@localhost updates]# sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
[root@localhost updates]#
重啟jenkins即可
至此,jenkins安裝成功
接下來為配置項
腳本:
#!/bin/bash
#maven打包
mvn clean package
echo 'package ok!'
echo 'build start!'
cd ./abc
service_name="abc"
service_prot=0000
#查看鏡像id
IID=$(docker images | grep "$service_name" | awk '{print $3}')
echo "IID $IID"
if [ -n "$IID" ]
then
echo "exist $SERVER_NAME image,IID=$IID"
#刪除鏡像
docker rmi -f $service_name
echo "delete $SERVER_NAME image"
#構(gòu)建
docker build -t $service_name .
echo "build $SERVER_NAME image"
else
echo "no exist $SERVER_NAME image,build docker"
#構(gòu)建
docker build -t $service_name .
echo "build $SERVER_NAME image"
fi
#查看容器id
CID=$(docker ps | grep "$SERVER_NAME" | awk '{print $1}')
echo "CID $CID"
if [ -n "$CID" ]
then
echo "exist $SERVER_NAME container,CID=$CID"
#停止
docker stop $service_name
#刪除容器
docker rm $service_name
else
echo "no exist $SERVER_NAME container"
fi
#啟動
docker run -d --name $service_name --net=host -p $service_prot:$service_prot $service_name
#查看啟動日志
#docker logs -f $service_name
7. 搭建完成,點擊啟動你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧
網(wǎng)站標題:jenkins自動化部署搭建-創(chuàng)新互聯(lián)
URL網(wǎng)址:http://www.rwnh.cn/article28/ddcjcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站建設(shè)、標簽優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站改版、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容