准备jenkins和gitlab的安装,这个过程请自行谷歌,介绍一下软件版本:
需要添加的插件:Gitlab Hook、Build Authorization Token Root、Gitlab Authentication、Gitlab
在 http://download.ceph.com/tarballs/ 下载对应的软件包版本,以12.2.12为例
解压软件包
[root@demohost1 supdev]# tar zxf ceph-12.2.12.tar.gz #解压
[root@demohost1 ceph-12.2.12]# cd ceph-12.2.12
[root@demohost1 ceph-12.2.12]# ls
admin ceph-erasure-code-corpus ChangeLog CONTRIBUTING.rst debian do_freebsd.sh fusetrace make-apk.sh man pom.xml README.alpine.md README.solaris share udev
alpine ceph-object-corpus cmake COPYING doc Doxyfile INSTALL make-debs.sh mirroring qa README.FreeBSD README.xio src
AUTHORS ceph.spec CMakeLists.txt COPYING-GPL2 doc_deps.deb.txt etc install-deps.sh make-dist NEWS README README.git-subtree run-make-check.sh SubmittingPatches.rst
bin ceph.spec.in CodingStyle COPYING-LGPL2.1 do_cmake.sh examples keys make-srpm.sh PendingReleaseNotes README.aix README.md selinux systemd
[root@demohost1 ceph-12.2.12]# find . -name ".gitignore"| xargs rm -f #关键步骤,剔除掉.gitignore,不然后面编译依赖检查会报错
初始化git,提交到gitlab仓库
[root@demohost1 ceph-12.2.12]# git init
Initialized empty Git repository in /home/supdev/ceph-12.2.12/.git/
[root@demohost1 ceph-12.2.12]# pwd
/home/demo/ceph-12.2.12
[root@demohost1 ceph-12.2.12]# git remote add origin http://gitlab.cephdemo.local/diluga/ceph.git
[root@demohost1 ceph-12.2.12]# git add --all .
The file will have its original line endings in your working directory.
warning: CRLF will be replaced by LF in src/rapidjson/thirdparty/gtest/googletest/msvc/gtest_unittest.vcproj.
The file will have its original line endings in your working directory.
[root@demohost1 ceph-12.2.12]# git commit -m "Initial commit"
[master (root-commit) 85a9fab] Initial commit
Committer: root <root@demohost1.h.chinabank.com.cn>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email you@example.com
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
The file will have its original line endings in your working directory.
46084 files changed, 9316748 insertions(+)
create mode 100644 .gitmodule_mirrors
create mode 100644 .gitmodules
...
create mode 100644 udev/60-ceph-by-parttypeuuid.rules
create mode 100644 udev/95-ceph-osd.rules
[root@demohost1 ceph-12.2.12]# git push -u origin master
Username for 'http://gitlab.cephdemo.local': diluga
Password for 'http://diluga@gitlab.cephdemo.local':
Counting objects: 48328, done.
Delta compression using up to 32 threads.
Compressing objects: 100% (47048/47048), done.
Writing objects: 100% (48328/48328), 83.34 MiB | 8.29 MiB/s, done.
Total 48328 (delta 12162), reused 0 (delta 0)
remote: Resolving deltas: 100% (12162/12162), done.
To http://gitlab.cephdemo.local/diluga/ceph.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
新建一个自由风格的软件项目,输入"rpmbuilid_ceph"
之后在源码管理里面选择git,输入之前新建的gitlab项目信息,设置相应的分支,这里选的是默认master分支
Credentials部分,选择“添加”,输入gitlab的账号和密码如下
之后设置 构建触发器,选择“Build when a change is pushed to GitLab”,记录“GitLab webhook URL”,选择在 “Push Events” 和 “Accepted Merge Request Events” 两种事件类型的时候触发webhook通知。
同时在Secret token 点击“Generate”,记录生成的token字段
最后选择"构建” -> "执行 shell",输入对应的rpm编译打包脚本,点击保存,完成jenkins设置。
脚本如下
#!/bin/bash
rm -rf ~/rpmbuild
/usr/bin/rpmdev-setuptree
cp -f ./ceph.spec ~/rpmbuild/SPECS
#git archive master --prefix=ceph-12.2.12/ | bzip2 > ceph-12.2.12.tar.bz2
mkdir ceph-12.2.12
mv * ceph-12.2.12
cp .gitmodules ceph-12.2.12
tar -cvjSf ceph-12.2.12.tar.bz2 ceph-12.2.12
cp ceph-12.2.12.tar.bz2 ~/rpmbuild/SOURCES/
cd ~/rpmbuild
/usr/bin/rpmbuild -bb SPECS/ceph.spec
打开gitlab 对应的项目,在 settings -> integrations
输入之前的“GitLab webhook URL” 和 token,勾选 push和 merge 两种类型的事件,如果没用到SSL,则取消SSL认证。
回到jenkins对应的"rpmbuild_ceph"任务列表,点击“立即构建”,开始编译ceph的rpm包,
编译过程可以通过点击具体任务,查看“控制台输出”,看到编辑的当前进度状态。
编译完成后,RPM包会存储在jenkins节点的/root/rpmbuild/下。
上面的设置需要注意的有3点
ceph.spec 内容片断
Summary: User space components of the Ceph file system
License: LGPL-2.1 and CC-BY-SA-3.0 and GPL-2.0 and BSL-1.0 and BSD-3-Clause and MIT
%if 0%{?suse_version}
Group: System/Filesystems
%endif
URL: http://ceph.com/
Source0: http://ceph.com/download/ceph-12.2.12.tar.bz2 #注意软件包名称