资源描述
接口平台环境搭建文档
.Jenkins■心做I室 MJHwtxy
& E知4又国由 Lockatte ResourcesWelcome to Jenkins!
Ptofc. mm new: g sunadtMMQiMueNobuMs HIM queue新建节点
点击图中标记连接:
■ New 曲& People"> Build History<\ Project Reiatkxtship
Welcome to Jenkins!
Ptease create new jobs to get 如/
匚 Check File Fingerprint ^s««a%ELockaNe ResourcesBuild Queue
No buids in ths qu«uoBuild Executor Status• masterIdle
1 Idle点击图中标记按钮
卷 Jenkins
Jenkins ►节点列表
■ Back to Dashboard
* Manage Jenkins 急 New Node J^Configure
Build Queue
No builds in the queue
Build Executor Status
更master
1 Idle
2 Idle输入名字jenkins-slave,勾选固定节点,并点击ok,如下图所示
Jenkins ♦点肉 H■ Back to Dashboard 令 Manage Jenkins
■ Back to Dashboard 令 Manage Jenkins
■ Back to Dashboard 令 Manage Jenkins
New Node
Node nag
令 Configuce
a plain permanent agnt to Jenkins This ts =3 •permdnenf because Jenkm ctoesn t provide higher level of Integration with dQents. such as dynamic provisioning Soled this type K no other a“nt t)p«$ app” 一 foe example such when you are XAng g physical computer. Eu* machines managed oulskto J^nkin$ etc
OK
Build Qu«im
No buWs In the que^ie
Build Executor Simus输入如下信息,并点击add添加秘钥王机
王机
|«<Wdns-slav0
L无-,
l| ~,
❷
Iha Mtocted crodMdals cannot ba found
Laioch agent agerAz & SSHJanklnb »伺点殖I
■ Back to DashooardNg
gnaaessg 岫
■ New Node
▲ c . 一■ of executors
* Conftgure
Romdo root directory
Build Ou«uo■
No bulds in the queueLgU
Us>QQ
Build 匚xQcirtoc Status■
1 WleLaunch method
2 Idlo
H»«K^ Verified suwegy Kno^ hoets Verification St>«t«9r添加凭据密码和用户名都必须为root,如下图所示:
Domain全局凭蹇(unrestricted)Username with password全局(Jenkins, nodes, items, all child items, etc)
UsernamerootPassword••••
ID添加完成后,更新以下信息并保存:
AvalaMtyNode PropertiwiMnch >9^ SSH顼
CredenfakD$aW•如mdon M nod«G认浅建节点就创建完成,如下图所示:并点击图中标记连接
Jenkins ,千南脆♦ Back to OashboaroManage Jenkins
Ne^rNoce令 ConfigureDISABLE AUTO REFRESH
$
Name .
明余交雄网
1
Linux (amd64)
32 88G8
387 G8
32 88G8
157ms 冷
mg弦
Linux (amd$4)
32 88 G8
387 68
J288G0
Oto专
Dau obalned
8J
8"
8.S»
8.6b
8.6 »
Build QueueNo bulds in the queueBuild EuoiUM SutiM• master
1 Idleidlejt jankins slavs1 Idle
进入以下界面,并点击图中标记按钮:
Jenkins ►节点列 SS ► master
■ Back to List
(入 Status
| / Configure
N Build History
S3 Load statistics
T Script Console
JJi Master (Jenkins的master节点)Projects tied to masterNone
Build Execuior SiatusIdleIdle出现以下界面,更新标记信息,并保存:
Jenkins ,方点切衰 • masier■ Back to L&Q Status.Configurt
乏 Build ustoryO Load Statistics3 script ConsoleBuild
1 g
2 Ide3 of executorsLabelsUsage
Nodo Prop«rt»asDtsablo WScrX wipoout on this nod«
点击标记连接回到首页。
曷 Jenkins
、enkins ▼节点列表► masterBack to ListStatus
Master (Jenkins的master节点)
Projects tied to master
None
,Configure
> Build History
E3 Load StatisticsScript Console
Build Executor Status1 Idle 2 Idle创建一个任务
点击图中标记按钮:
Genet alBuW Triggers Advanced Project Options
Definition Pipeline script
Pipeline
Scnpt
try sample Pipeline ▼
e)
✓ Use Groovy Sandbox
Q>
更新信息,并点击add>ymax
Sample Stepi gk: GhRepository URL
Repository URL
Repository URL
项目的git地址
https7/pms going-link com/source/general-interface-platform ghFailed to connect to repository : Command "git Is-remote -h b J stdout:
stderr: fatal: unable to access 'https://pms.golng- The requested URL returned error: 403Branch
Branch
Branch
master
Credentials
•无・
'Include in polling^ 'Include in changelog^
Generate Pipeline Script添加git的凭据:
人击Jenkins凭据提供者:JenkinsA物凭据
Domain 全局凭穿(unrestricted)
Username with password
接着选择添加的凭据,并点击生成脚本:
Sample Step Git'Indude in changelog?
'Indude in changelog?
Generate Pipeline Script
git aedentialsld 21419'. uri: ' going-link com/source/general-interface-platform.git'
更改附件脚本.txt中的标记代码,并复制,如下图所示:
node(
try(
stageCapp1) (凭据id
sh 'rm -rf general-interface-platform'
withCredentials((usernamePassword(credentialsld: [21419*, passwordvariable: 'GIT PASSWORD', usernameVariable: GITJJSERNAME*)]) {
shCgit done — branch master')
}
dir(*general-interface-platform")(
sh 'mvn clean package'
sh ,docker build -t general-interface-platform
sh 'docker rm -f general-interface-platform || true'
sh 'docker run -d —name general-interface-platform -p 9000:9000 general-interface-platform'
sh 'docker images | grep none | awk \'{print $3}\,| xargs -I — docker rmi -f — || true'
项目git地址
Jcatch (e) ( currentBuild.result ■ "FAILED, throw e
}
点击back,并返回
片段斯38
Declarative DrecUve Gentfac<x
Declarative Onire Documefitati
蝴di”
mtelU IDEAGDSL
Overview
Thb Snippet Genetator w« help you learn the Rpefine Script code which can be used Io ddne rarious steps Pick a step you ate intere«ted in from the fist, configure it did Generate Pipeline Script and you H sm a Kpefine Script sUtement that would cal the step wifi that cccvfiguration Ybu may copy and paste the sUlamant into your script or pid up just the opdom you cara about (Mosl param«ters as optional and can bo ofnittod in your Kript laavng them at dafaUI vakms)
Steps
Sample Step,
© Reposiior/ URL^bg-li*. coovwurgjenwMrterfac+phtfMm gi!
Branch
Cfe^enUato
master
, Indude m poMng^
♦ Include In chan^og^
出现如下界面,并点击配置
Jenkins ► general-interface-platform
Back to DashboardStatusChanges立即构建
RenameBuild HistoryConfigure•女三Q 0
Delete PipelineFull stage viewPipeline Syntaxtrgn。
findRSS for all RSS for failures将配置的脚本粘贴到图中,并保存Jenkins ♦ general-mterfdce-p*^^
General Buid Trtggers Advanced Propel OptionsPipelineDefini6onScript
Pip«lin«PipelineRec—nt ChanqStage View
No data available ThisPermalinksS{ try( stageCW)( sh -rf eenerai - interface-platforw , withCredentiels((userna»»ePds$»»rd(cr«knti«lsId: • 21419'» p«sswor(JVarieble: '6IT_i4aS! shCgit clone https://${6IT_US£RMWJ:$(GIT_PASSWOftO}fp«.soing-link.cai/50ur< e/|dlrCgener*l-interf«ce-pl«tfoni")(
•wn clean peck^ce* docker build -t general-interface*platfom .• docker rw -f general-interface*platfora || true"dicker 心・d ・・m ce neral • interface - plat for® -p 9««:900« central, inte f>« docker iitaces | <rep none | i {print | xorgs -I -- docker r«i —(e) (5 Use Groovy Sandbox
Piome Syntax
保存完成之后,点击立即构建。
Jenkins > general-interface-platformBack to Dashboard(、StatusPipeline general-interface-platform
,Changes0立即构建0 DeletFPipeline 整 Configurey Recent Changes
Full Stage View"x* RenameQ Pipeline SyntaxStage View
No data available This Pipeline has not yet run.
findBuild Historytrend不 Permalinks
t& RSS for all 闵 RSS for failures等待其构建完成,就可以访问项目了。
4附件:
注意:在之后每次更新代码都要手动构建一次项目。
□ ■
docker-compos脚本.txte.yml
文档控制记录更改审阅人
日期作者版本文档状态更改参考
姓名职位
分发
拷贝号姓名职位
1
2
3
4
文档目录文档控制2文档目录31安装软件4
1.1安装并启动docker41.2 安装 dockcr-composc52创建并启动容器62.1创建容器6
3打开Jenkins并进行配置73.1 Jenkins 配置74附件:19
1安装软件
在服务器上需要安装docker和cocker-compose,以下教程使用centos 7服务器并使用root户。 其它类型服务器安装见官网:
httDS:〃
注意:以上网站需要翻墙。在之后每次更新代码都要手动构建一次项目。
1.1安装并启动docker卸载旧版本的docker,命令如下:
$ sudo yum remove docker \docker-client \docker-client-latest \docker-common \
docker-latest \docker-latest-logrotate \docker-logrotate \docker-selinux \
docker-engine-selinux \docker-engine安装系统插件和存储库,命令如下:
$ sudo yum install -y yum-utils \
device-mapper-persistent-data \
lvm2安装源,命令如下:
$ sudo yum-config-manager \
--add-repo \
注意:可能安装失败,请更换源,提供国内源,命令如下:
$ sudo yum-config-manager --add-reporepo安装docker,命令如下:
$ sudo yum install docker-ce启动docker,命令如下:
$ sudo systemctl start docker
2创建并启动容器2.1创建容器创建目录并进入,其命令如下:
inkdir docker-compose
cd docker-compose/创建文件docker-compose.yml,其命令如下:
vi docker-compose.yml
按i键并将附件中的内容复制进去,按esc并输入:wq报存并退出。
启动容器,其命令如下:
docker-compose up -d
执行完成后,执行以下命令(分条执行):
docker-compose down
sudo chmod -R 777 data/
docker-compose up -d
3打开Jenkins并进行配置
本节介绍jenkins实现项目部署。
3.1 Jenkins 配置3.1.1 访问 jenkins
打开浏览器输入:http://ip:8080并访问,注意ip为服务器的ip地址。如下图所示:
Getting StartedUnlock JenkinsTo ensure Jenkins is securely set up by the administrator, a password has been written to the log (noi sure where to find 2) and this file on the server:
/var/Jenkins_ho®e/secrets/initialAdiiinPasswordPlease copy the password from either location and paste it below.
Admirastralor passwordContinue
打开服务器,输入如下命令:
docker ps
将图中标复制下来[。月 11月 11月
[。月 11月 11月
[。月 11月 11月
-rw-r--r—. 1 root root 9063S87 drwxr-xr-x. 3 root root drwxr-xr-x. 6 root root [root@localhost -]# docker CONTAINER IDIMAGE
MES 014aeb7cba64
ocker-con¥>O3e_jenkins-31ave_l_9d8025b6€4ee 341066d88f5b
44
99
PS
25 03:20
16
15
00:05
04:53
COMMAND
CREATED
STATUS
■/uar/local/bin/mvn--.'
2 hours ago
jenkinsci/jenkins:2,147-alpine
■/sbin/tini — /usr/_ "
2 hours ago
Up 2 hourJ
ocker-conf>ose_jenkins_l_8ea6<if327aa4 [root@localhost|
输入以下命令,注意用上刚才复制的内容,将命令中的替换掉。
sudo docker exec -it d6a4b9b037de /bin/bash
出现如卜-界面:
[root@localhost ~]♦ sudo docker exec -it 341066d88f5b /bin/bash bash-4.4$ |
并输入以下命令:
cat /var/jenkins home/secrets/initialAdminPassword
将图中内容复制并粘贴到页面的输入框中,并点击继续。
Getting Started
Continue
Unlock Jenkins
To ensure Jenkins is securely set up by the administrator, a password has been written to the log (no【sure where 10 find i【?) and this file on the server:
/var/jenkins_home/secrets/initialAdminPassword
Please copy the password from either location and paste it below.
Administrator password
3.1.2 配置Jenkins
选择推荐插件并继续,会出现插件安装,如下图所示:
uenmg dianeaCustomize JenkinsPlugins extend Jenkins with additional features to support many different needs.
Install suggested pluginsInstall plugins the Jenkins community finds most useful.
Select plugins to installSelect and install plugins most suitable for your needs.
Gening StartedGetting StartedV FoMwt
|G OMiASP Markup
O 24 T«n«ou1
0岫〜
F«14«rs •• JIK T«*l ・・ *4vi»t Zwwity
O
Timejtinxxf
G Wo<kso*c« Ctewup
G
Am
G Grxfe
O
O MHA Branch
O
0mu>0f0<r/y
OV>w
O
on
O
G
O Mltn. AUtWUKS
O
PAM AuthKi^bon
Q LDAP
O
(nw<(rtfnpen
0
V FoMwt
|G OMiASP Markup
O 24 T«n«ou1
0岫〜
F«14«rs •• JIK T«*l ・・ *4vi»t Zwwity
O
Timejtinxxf
G Wo<kso*c« Ctewup
G
Am
G Grxfe
O
O MHA Branch
O
0mu>0f0<r/y
OV>w
O
on
O
G
O Mltn. AUtWUKS
O
PAM AuthKi^bon
Q LDAP
O
(nw<(rtfnpen
0
插件安装完之后,设置管理员账号信息,如下图所示:
Getting StartedCreate First Admin UserFulnam*
147
Saw and CorOnue接下来一次点击继续,直到出现以下界面,如下图所示:
Getting StartedJenkins is ready!
Your Jenkins setup is complete.
Start usmg J«nkM
J«nkms 2.147点击开使用Jenkins,出现以下界面,如下图所示:
展开阅读全文