Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...?

like image 457
Sagar Avatar asked Apr 22 '13 20:04

Sagar


2 Answers

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.

like image 152
thekbb Avatar answered Sep 20 '22 20:09

thekbb


I've been using the Jenkins build number as the 'release' and packaging via fpm.

Couple fpm with some globals provided by Jenkins

# $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.

There's some nebulous variables in the example command below, but $BUILD_NUMBER is what I'm using for the release here (fpm calls it iteration instead).

fpm_out=$(fpm -a all -n $real_pkg_name -v $version -t rpm -s dir --iteration $BUILD_NUMBER ./*)
like image 25
quickshiftin Avatar answered Sep 19 '22 20:09

quickshiftin