Building an rpm file with a unique qualifier appended

Solution 1:

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.

Solution 2:

The problem with this approach is that such specs require an externally-defined parameter (buildnumber)... for example re-building an .src.rpm file will most probably yield a different version number than the one originally used by your CI system.

I think what you really want is embed the source version (e.g., subversion revision number) into the RPM version number. I generate RPM .specs from templates. The template is source-controlled and the build process generates a real spec file from it, so

Version: 1.0.beta7.svn@SVN_REV@ 

becomes something like

Version: 1.0.beta7.svn1234