在RPM spec文件中使用Jenkins BUILD NUMBER

问题描述 投票:8回答:3
Name:                   My Software
Version:                1.0.5
Release:                1
Summary:                This is my software

不确定是否有人之前尝试过此操作或是否容易,但是:

spec文件的版本有两个唯一的指标:

  • 版本(指定软件版本)
  • 释放(指定包的编号 - 如果您构建一个RPM,它已经破坏,并构建另一个,您可以使用'Release'编号。

我想知道是否有人尝试或知道如何使用Jenkins $ BUILD_NUMBER变量来动态更改Release数,从而每次新的成功构建完成时都会增加Release数量?

linux jenkins rpm rpmbuild rpm-spec
3个回答
7
投票

这已经很久了......谢天谢地,我没有基于rpm的系统,所以我无法测试这个。

您可以在命令行上将参数传递给rpmbuild

rpmbuild --define="version ${env.BUILD_NUMBER}"

发布规范的片段和用于构建rpm的脚本会很有帮助。你不希望你的构建脚本编辑spec文件,我假设它正在从某个源代码控制中删除。


3
投票

我一直在使用Jenkins构建号作为'发布'并通过fpm打包。

与詹金斯提供的一些全局变量结合fpm

# $BUILD_ID - The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
# $BUILD_NUMBER - The current build number, such as "153"
# $BUILD_TAG - String of jenkins-${JOB_NAME}-${BUILD_NUMBER}. Convenient to put into a resource file, a jar file, etc for easier identification.

下面的示例命令中有一些模糊的变量,但$BUILD_NUMBER就是我在这里发布的(fpm称之为迭代)。

fpm_out=$(fpm -a all -n $real_pkg_name -v $version -t rpm -s dir --iteration $BUILD_NUMBER ./*)

3
投票

在我的Jenkins设置中,我决定完全绕过关于RPM版本编号的内部版本号。相反,我使用自制脚本生成并跟踪正在生成的各种版本。

在我的spec文件中:

Version:    %{_iv_pkg_version}
Release:    %{_iv_pkg_release}%{?dist}

在Jenkins构建脚本中:

# Just initialising some variables, and retrieving the release number.
package="$JOB_NAME"
# We use setuptools, so we can query the package version like so.
# Use other means to suit your needs.
pkg_version="$(python setup.py --version)"
pkg_release="$(rpm-release-number.py "$package" "$pkg_version")"

# Creating the src.rpm (ignore the spec file variables)
rpmbuild --define "_iv_pkg_version $pkg_version" \
    --define "_iv_pkg_release $pkg_release" \
    -bs "path/to/my/file.spec"

# Use mock to build the package in a clean chroot
mock -r epel-6-x86_64 --define "_iv_pkg_version $pkg_version" \
    --define "_iv_pkg_release $pkg_release" \
    "path/to/my/file.src.rpm"

rpm-release-number.py是一个简单的脚本,它维护一个基于文件的数据库(采用JSON格式,便于维护)。它可以处理同时运行,所以不用担心,但如果你有构建奴隶就行不通(据我所知,我不使用它们因此无法测试)。你可以找到源代码和文档here

结果是我得到以下包版本控制方案:

# Build the same version 3 times
foo-1.1-1
foo-1.1-2
foo-1.1-3
# Increment the version number, and build twice
foo-1.2-1
foo-1.2-2

PS:请注意,Jenkins构建脚本只是一个示例,创建rpmbuild目录结构并检索.src.rpm和.spec文件名的逻辑有点复杂。

© www.soinside.com 2019 - 2024. All rights reserved.