Search code examples
linuxjenkinsrpmrpmbuildrpm-spec

Using Jenkins BUILD NUMBER in RPM spec file


Name:                   My Software
Version:                1.0.5
Release:                1
Summary:                This is my software

Not sure if anyone has tried this before or if it is easy, but:

A spec file has two unique indicators for its version:

  • Version (which specifies software version)
  • Release (which specifies the package's number - if you build an RPM, it's broken, and build another one, you up the 'Release' number.

I'm wondering if anyone has tried, or knows how, I could use the Jenkins $BUILD_NUMBER variable to dynamically change the Release number, thereby increasing the Release number every time a new successful build completes...?


Solution

  • It's been a long time... and thankfully I have no rpm based systems so I can't test this.

    You can pass parameters to rpmbuild on the commandline

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

    It would be helpful to post snippets of the spec and the script you're using to build the rpm. You don't want your build script editing the spec file, which I'm assuming it's pulling out down from some source control.