我在Hudson中设置了一个C项目,进行每夜构建,并有一个.rpm规范文件用于从这些源代码创建rpms。
请问是否有任何经验可以利用Hudson构建所有这些的rpm?
目前,我唯一看到的解决方案是设置一个作业运行一个脚本,检查svn导出源代码,创建tar包并完成整个rpm构建。这似乎与Hudson集成不良 - 例如,我如何收集工件?
我现在已经为两个项目完成了这项工作。这并不难,但取决于你的工作流程。最重要的问题是:在构建完该软件包后,你想要做什么?在我的上一个项目中,软件包只是上传到了代码库,因此我不需要收集任何工件。
无论如何,以下是我的一些提示:
.rpmmacros
. Mine looks just like %_topdir /srv/build
, but you are of course free to define more macros there.rpmbuild -bb project.spec
on it. Since this script also uploaded the RPMs to the repository, I didn't need anything else besides this single script, meaning I actually used Hudson like an advanced cron manager (automatic build three times a day, manual builds on mouse click). It was still SVN-triggered though, so that we didn't build unnecessarily.I wanted to have clean packages and also retain the possibility to build from command-line. For that reason, my RPM spec created its own tarball automatically from an SVN export. I've taken the exporting functionality out for current project, so it looks like this now:
%define module my_project
%define _curdir .
%define _release %(/usr/bin/svnversion -c %_curdir | %__sed 's/.*://g')
%define _moddir %module-%_version-%_release
%define _source %(/bin/tar czf %_sourcedir/%_moddir.tar.gz --transform="s|^./|%_moddir/|g" --exclude=.svn .; /bin/echo %_moddir.tar.gz)
and later in the spec:
Source0: %_source
In my current project, I've split that script up into parts, so that my current Jenkins job only consists of rpmbuild ...
command. The reason was that I didn't need to build from different branches.
总之,可以通过Jenkins构建RPM包,这相当容易,因为难点在于创建一个干净的RPM规范。其他所有内容都取决于您的需求,可以通过一些脚本或Jenkins插件来解决。
我同意上述观点——一旦你可以从任何目录创建RPM包,你就可以编写脚本来构建过程,并直接将其放入Hudson。
这里是魔法所在:
rpmbuild --define '_topdir '`pwd` -ba SPECS/helloworld.spec
这将把当前目录设置为构建过程的顶级目录。
我曾经遇到相同的问题,并在以下网址上记录了完整的过程:
http://www.itforeveryone.co.uk/rpm-build-hudson-jenkins.html
Ant可以通过内置的RPM任务来构建RPM包。
您可以使用Ant-contrib中的CC任务编译C源代码。
然后,您可以使用Hudson来构建和打包我们的软件。
曾经,我用一个自定义的Scala插件替换了上面提到的Maven DSL,部分原因是为了学习Scala。它确实满足了一些更多的需求。但现在,我只会推荐使用fpm,它在90%的rpm创建需求中表现出色(也支持deb等)。
export PROJECT_NAME=
export PROJECT_VERSION=
#Cleanup
rm -f /tmp/JENKINS-BUILD/SPECS/$PROJECT_NAME.rpm.spec
rm -Rf /tmp/JENKINS-BUILD/SOURCES/$PROJECT_NAME /usr/src/redhat/SOURCES/$PROJECT_NAME
#Copy sources/artifacts
cp /var/lib/jenkins/jobs/$PROJECT_NAME/workspace/project-set/$PROJECT_NAME/showme/include/$PROJECT_NAME.rpm.spec /tmp/JENKINS-BUILD/SPECS/$PROJECT_NAME.rpm.spec
cp -R /var/lib/jenkins/jobs/$PROJECT_NAME/workspace/project-set/$PROJECT_NAME/showme /usr/src/redhat/SOURCES/$PROJECT_NAME
cp -R /var/lib/jenkins/jobs/$PROJECT_NAME/workspace/project-set/$PROJECT_NAME/showme /tmp/JENKINS-BUILD/SOURCES/$PROJECT_NAME
#Build RPM
rpmbuild --define 'BUILD_NUMBER '$BUILD_NUMBER -ba /tmp/JENKINS-BUILD/SPECS/$PROJECT_NAME.rpm.spec --define '_topdir '/tmp/JENKINS-BUILD/
cp /tmp/JENKINS-BUILD/RPMS/noarch/$PROJECT_NAME-$PROJECT_VERSION-$BUILD_NUMBER.noarch.rpm /var/lib/jenkins/jobs/$PROJECT_NAME/workspace
(感谢JT/JWT)
经过查阅许多博客文章和其他资源的信息,我将它们合并成一个脚本,可以轻松地在Jenkins中用于构建软件包:https://github.com/jhrcz/jenkins-rpm-builder。
它以yum仓库的形式收集工件(rpm软件包),因此通过一些配置,httpd可以指向最新的稳定版本仓库。
在代码中,您可以发现它支持软件包签名,并尝试解决el5和el6之间所需的所有差异。