Building an rpm file with a unique qualifier appended

rpm

I'm building RPMs in a continuous integration environment, and I need to distinguish between successive builds, but obviously the spec file does not get modified on each checkin.

The spec file header contains something like

Version:        1.0beta7
Release:        1.1

I'd like to override it so that the the built RPM will have a qualified appended to the version, e.g.

Version:        1.0.beta7.2913

Assuming that the qualifier is already available, as an environment variable, what's the easiest way of appending a qualified to the version?

Best Answer

Fairly easy:

Version: 1.0.beta7.%(echo $ENVVAR)

You can run whatever command you want inside %(); just make sure there's no whitespace in the output.

Personally, I think it's a touch cleaner to stick it in a variable at the top:

%define buildnumber %(whatever command to get the build number)

Version: 1.0.beta7.%{buildnumber}

Or to make it conditional on the variable being set:

Version: 1.0.beta7%{?buildnumber:.%{buildnumber}}

That should only print the '.' if %buildnumber is set.

Related Topic