本文主要介绍基于Jenkins搭建Tars-C++服务的CI/CD工程,实现Tars服务的持续集成和持续发布,全程界面化 *** 作。
前提
- Jenkins搭建完成
- Jenkins-worker上安装了编译环境
- Tars框架已存在,目标服务已发布
1、创建自定义工程
这个步骤很简单,按照下图进行即可。
2、参数化构建
按需设置参数,若想灵活设置,可以参考我的设置,参数包括:
- 控制台IP:PORT
- Tars应用名
- Tars服务名
- 发布备注信息
- 可执行程序名
控制台地址和应用名:
要发布的服务名和备注信息:
构建的目标文件:
3、源码管理
在这里配置SCM拉取版本库的代码。
构建触发器需要配置下:
每2分钟扫描一次版本库。
4、构建步骤
- 增加构建步骤-Cmake Build
在这里指定【源码目录】,./dataServer是从版本库拉取过来的。
指定构建的目录build,即在工作目录下会自动创建一个build目录,cmake后的文件都会放在build下。
- 增加构建步骤-执行shell
编写shell脚本,将生成的可执行文件打包。
其中变量${TARGET}是从步骤2中继承过来的,即生成的可执行文件名。
说明:
shell脚本中的核心逻辑是参考Tars框架打包步骤编写的。
其中部分内容做了个性化处理,按需选用。
- 增加构建步骤-执行shell
执行shell指令,将发布包发送到TarsWeb控制台。
完整的指令:
cd ./dataServer
curl http://${IP_PORT}/api/upload_and_publish?ticket= -Fsuse=@${TARGET}.tgz -Fapplication=${AppName} -Fmodule_name=${ServerName} -Fcomment=${comments}.`date +%Y%m%d%H%M%S`
5、执行构建
如果在SVN上修改代码、提交之后,会自动触发编译构建并自动发布,部分日志展示如下:
Started by an SCM change
Running as SYSTEM
Building remotely on node_10.4.120.170 (develop) in workspace /home/jenkins/workspace/billapp-dataDealServer
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Deferred wipeout is used...
[WS-CLEANUP] Done
Checking out a fresh workspace because /home/jenkins/workspace/billapp-dataDealServer/dataServer doesn't exist
Cleaning local Directory ./dataServer
Checking out https://10.4.121.12:8090/svn/CUG_MVNE/trunk/CUG_MVNE_OCS/src/tarsTest/billapp_ at revision HEAD --quiet
Using sole credentials li-qzh/****** (svn-liqzh) in realm ‘ CollabNet Subversion Repository’
At revision 5999
WARNING: clock of the subversion server appears to be out of sync. This can result in inconsistent check out behavior.
Checking out a fresh workspace because /home/jenkins/workspace/billapp-dataDealServer/pubtable doesn' t exist
Cleaning local Directory ./pubtable
Checking out https://10.4.121.12:8090/svn/CUG_MVNE/trunk/CUG_MVNE_OCS/src/tarsTest/pubtable at revision HEAD --quiet
Using sole credentials li-qzh/****** (svn-liqzh) in realm ‘<https://10.4.121.12:8090> CollabNet Subversion Repository’
At revision 5999
WARNING: clock of the subversion server appears to be out of sync. This can result in inconsistent check out behavior.
Checking out a fresh workspace because /home/jenkins/workspace/billapp-dataDealServer/base doesn't exist
Cleaning local Directory ./base
Checking out https://10.4.121.12:8090/svn/CUG_MVNE/trunk/CUG_MVNE_OCS/src/tarsTest/base at revision HEAD --quiet
Using sole credentials li-qzh/****** (svn-liqzh) in realm ‘ CollabNet Subversion Repository’
At revision 5999
…………
[billapp-dataDealServer] $ /bin/sh -xe /tmp/jenkins964449821044948467.sh
+ cp ./dataServer/dataCMakeLists.txt ./dataServer/CMakeLists.txt
[build] $ cmake /home/jenkins/workspace/billapp-dataDealServer/dataServer
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jenkins/workspace/billapp-dataDealServer/dataServer/build
[build] $ /usr/bin/gmake -j8
Scanning dependencies of target dataDealServer
[ 0%] [ 1%] Building CXX object CMakeFiles/dataDealServer.dir/service/data_exception_terminate.cpp.o
Building CXX object CMakeFiles/dataDealServer.dir/service/voice_preoccupation.cpp.o
[ 2%] Building CXX object CMakeFiles/dataDealServer.dir/service/UserOffline_service.cpp.o
[ 3%] [ 3%] Building CXX object CMakeFiles/dataDealServer.dir/service/sms_authentication.cpp.o
Building CXX object CMakeFiles/dataDealServer.dir/service/data_preoccupation.cpp.o
[ 4%] Building CXX object CMakeFiles/dataDealServer.dir/service/QueryDataUsage_service.cpp.o
………………
CMakeFiles/dataDealServer.dir/home/jenkins/workspace/billapp-dataDealServer/pubtable/acct/user_online_status.cpp.o
[ 99%] Building CXX object CMakeFiles/dataDealServer.dir/home/jenkins/workspace/billapp-dataDealServer/pubtable/acct/external_interface_call_error_t.cpp.o
[100%] Building CXX object CMakeFiles/dataDealServer.dir/home/jenkins/workspace/billapp-dataDealServer/pubtable/acct/network_element_queue_config.cpp.o
Linking CXX executable dataDealServer
[100%] Built target dataDealServer
[billapp-dataDealServer] $ /bin/sh -xe /tmp/jenkins7766459388228683320.sh
+ cp ./dataServer/build/dataDealServer ./dataServer
+ cd ./dataServer
+ echo ' begin make tars for dataDealServer'
begin make tars for dataDealServer
+ '[' -d dataDealServer_tmp_dir ']'
+ mkdir dataDealServer_tmp_dir dataDealServer_tmp_dir/dataDealServer
+ cp -rf dataDealServer dataDealServer_tmp_dir/dataDealServer/
+ cp -rf mysql.yaml dataDealServer_tmp_dir/dataDealServer/
+ cp -rf dcache.yaml dataDealServer_tmp_dir/dataDealServer/
+ cp -rf dal.xml dataDealServer_tmp_dir/dataDealServer/
+ cp -rf redlock.yaml dataDealServer_tmp_dir/dataDealServer/
+ cd dataDealServer_tmp_dir
+ tar --exclude=.svn --exclude=_svn -czvf dataDealServer.tgz dataDealServer/
dataDealServer/
dataDealServer/dataDealServer
dataDealServer/mysql.yaml
dataDealServer/dcache.yaml
dataDealServer/dal.xml
dataDealServer/redlock.yaml
+ cd ../
+ '[' -f dataDealServer.tgz ']'
+ mv dataDealServer_tmp_dir/dataDealServer.tgz ./
+ rm -rf dataDealServer_tmp_dir
+ echo 'tar cvfz dataDealServer.tgz ...'
tar cvfz dataDealServer.tgz ...
[billapp-dataDealServer] $ /bin/sh -xe /tmp/jenkins7330854507712114822.sh
+ cd ./dataServer
++ date +%Y%m%d%H%M%S
+ curl 'http://10.4.120.170:3000/api/upload_and_publish?ticket=' -Fsuse=@dataDealServer.tgz -Fapplication=billapp -Fmodule_name=dataDealServer -Fcomment=.20201110114754
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 66.3M 0 0 100 66.3M 0 66.2M 0:00:01 0:00:01 --:--:-- 66.3M
100 66.3M 0 0 100 66.3M 0 33.1M 0:00:02 0:00:02 --:--:-- 33.1M
100 66.3M 0 0 100 66.3M 0 22.0M 0:00:03 0:00:03 --:--:-- 22.1M
100 66.3M 0 0 100 66.3M 0 16.5M 0:00:04 0:00:04 --:--:-- 16.5M
100 66.3M 0 0 100 66.3M 0 13.2M 0:00:05 0:00:05 --:--:-- 13.2M
100 66.3M 0 0 100 66.3M 0 11.0M 0:00:06 0:00:06 --:--:-- 0
100 66.3M 100 295 100 66.3M 47 10.5M 0:00:06 0:00:06 --:--:-- 0
Method Not Allowed
patch serverId: 122, node_name: 10.4.120.170
-----------------------------------------------------------------
task no: [1f40c1a61adb4cdf897d1c83c26a489a]
10.4.120.170 EM_I_SUCCESS startServer [billapp.dataDealServer] from 10.4.120.170 :server is activating, please check:
Finished: SUCCESS
至此,实现了Tars服务的持续集成和持续发布。
结语
本文演示了通过Jenkins的参数化构建,利用已知的接口和工具,实现Tars-C++服务的持续集成和持续发布。希望对Tars开发者有所帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)