Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
This looks exactly what I'm looking for, I'll try it out. –  Robert Munteanu Nov 6 '09 at 16:17
    
Works great, one final question. I want to append the whole '.$ENVVAR' or nothing at all. How can do it so that I don't end up with a version of 1.0.beta7. (note the final dot) when ENVVAR is not set? –  Robert Munteanu Nov 6 '09 at 16:21
1  
Something like %{?buildnumber:.%{buildnumber}}. –  freiheit Nov 6 '09 at 16:56

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.