使用Hudson构建RPM包

12

我在Hudson中设置了一个C项目,进行每夜构建,并有一个.rpm规范文件用于从这些源代码创建rpms。

请问是否有任何经验可以利用Hudson构建所有这些的rpm?

目前,我唯一看到的解决方案是设置一个作业运行一个脚本,检查svn导出源代码,创建tar包并完成整个rpm构建。这似乎与Hudson集成不良 - 例如,我如何收集工件?

9个回答

2

我现在已经为两个项目完成了这项工作。这并不难,但取决于你的工作流程。最重要的问题是:在构建完该软件包后,你想要做什么?在我的上一个项目中,软件包只是上传到了代码库,因此我不需要收集任何工件。

无论如何,以下是我的一些提示:

  1. You'll need a build area for Hudson/Jenkins, it can be just a directory in JENKINS_HOME. You need to point rpmbuild to it via .rpmmacros. Mine looks just like %_topdir /srv/build, but you are of course free to define more macros there.
  2. In my last project, I needed to build RPMs either from intergration branches (in the integration time frame) or from trunk (outside of integration time frame). For that, I've built a Perl script, which checked out the correct branch depending on current date and ran 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.
  3. 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
    
  4. 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独立于svn脚手架之外构建时,如何使用build-a-tarball脚本?虽然很多人不运行这个测试,但确认独立构建的能力非常有价值。 - user2066657

2
我不确定我是否能给你一个很好的答案。对于你的需求,以下方法可能有些繁琐。
我曾使用过maven rpm插件http://mojo.codehaus.org/rpm-maven-plugin/,通过该插件创建spec文件、布置源码等,这样hudson可以更轻松地跟踪maven构件。
在maven构建中,我添加了一点groovy脚本(http://docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code)来自动更新托管构建的yum仓库,但在你的情况下,我可能会在使用rpm插件之前使用该脚本调用make。
说实话,我认为上述解决方案有些繁琐,主要是因为在maven中进行脚本编写时很啰嗦,但它确实有效,并且对于我们这些熟悉maven的Java开发人员来说,效果很好。

2

我同意上述观点——一旦你可以从任何目录创建RPM包,你就可以编写脚本来构建过程,并直接将其放入Hudson。

这里是魔法所在:

rpmbuild --define '_topdir '`pwd` -ba SPECS/helloworld.spec 

这将把当前目录设置为构建过程的顶级目录。

我曾经遇到相同的问题,并在以下网址上记录了完整的过程:
http://www.itforeveryone.co.uk/rpm-build-hudson-jenkins.html


1

我自己没有做过,但我认为你可以让Hudson构建rpms,但rpm构建区域在Hudson工作区内。然后,您将能够将rpms链接为工件。

这里是如何使用不同的rpm构建区域。


1
你在Hudson上使用什么构建工具?是Make吗?
你可以创建一个目录结构,用于Hudson作业的Workspace中的rpm构建 - 这可以已经在Hudson检出中,或者可以由构建脚本单独创建。从这个目录中,你可以创建你的rpms(使用从Hudson启动的外部进程?)。之后,你可以使用普通的Hudson配置设置将生成的rpm复制到artifacts目录中。(Hudson定义了许多环境变量,你可以使用其中之一来使用workspace位置)

1

Ant可以通过内置的RPM任务来构建RPM包。

您可以使用Ant-contrib中的CC任务编译C源代码。

然后,您可以使用Hudson来构建和打包我们的软件。


1

0
这是我们使用的 Jenkins shell 脚本:
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)


0

经过查阅许多博客文章和其他资源的信息,我将它们合并成一个脚本,可以轻松地在Jenkins中用于构建软件包:https://github.com/jhrcz/jenkins-rpm-builder

它以yum仓库的形式收集工件(rpm软件包),因此通过一些配置,httpd可以指向最新的稳定版本仓库。

在代码中,您可以发现它支持软件包签名,并尝试解决el5和el6之间所需的所有差异。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接