How to use environment variables in the header of RPM spec file (for Version)?

Viewed 992

I have a .spec file for rpmbuild

Name:           my-product
Version:        %{getenv:VERSION}
Release:        1%{?dist}
Summary:        ENTER SUMMARY HERE
Group:          Miscellaneous
License:        Custom

I use it in docker and want to run a container with specific environment variables and substitute it in spec file
Is it possible?

1 Answers

You can pass them in as macros:

rpmbuild -ba --define "version_ ${VERSION}" myspec.spec

Then in the specfile:

Version: %{version_}

I used the trailing "_" to avoid conflicts with the predefined variables.

Related