Issue
Building an RPM is part of our CI-flow, so naturally I want the version number passed as a parameter into rpmbuild
, but I can't get it to work. I tried the solution from href="https://stackoverflow.com/questions/21559477/how-to-pass-user-defined-parameters-to-rpmbuild-to-fill-variables">this question, but it says I can't put '$' in define-strings:
[mangolorax@localhost build_artifacts]$ ./package_release.sh 1.3.3.7
+ BUILD_VERSION_STRING=1.3.3.7
+ BUILD_DIR=/home/builder/build
+ exec rpmdev-setuptree
+ cd /home/mangolorax/rpmbuild/SPECS/
+ ln -sf /home/builder/build/mvpn.spec
+ rpmbuild --target x86_64 --define 'version ${BUILD_VERSION_STRING}' -bb mvpn.spec -vv
Building target platforms: x86_64
Building for target x86_64
error: line 2: Illegal char '$' in: Version: ${BUILD_VERSION_STRING}
I also found this question, but it seems to me to be a ridiculously convoluted solution to the problem. Surely there must be a simpler way of doing this? Or have I fundamentally misunderstood this problem?
Solution
The entire problem was that I used single quotes around the --define
string. In bash
that means that everything inside the string is passed literally without expanding any variables. If I call rpmbuild
like this instead, it works as expected:
rpmbuild --target x86_64 --define "version ${BUILD_VERSION_STRING}" -bb mvpn.spec -vv
Answered By - Fylke Answer Checked By - Clifford M. (WPSolving Volunteer)