<#12797 Support for Environment variables in BUILD...
# github-notifications
q
#12797 Support for Environment variables in BUILD files. Issue created by xlevus Is your feature request related to a problem? Please describe. In two cases I've written a plugin that needs to access environment variables, and will need to write a third. Two of which, are documented cases for writing plugins. • Plugin to take the
$VERSION
variable and insert it into
setup_py()
• Username/Password for a PyPi repository • (to come) take
$VERSION
and use it as the
docker_image(version=
. It would be much easier if by default these fields could take environment variables by default. Describe the solution you'd like An
Env
'function' in
BUILD
files to denote the value of that field is to be taken from an environment variable.
Copy code
python_distribution(
  ...
  setup_py(
    version=Env('VERSION'),
  )
)

docker_image(
  ...
  version=Env('VERSION'),
)

pypi_repository(
  password=Env('PYPI_PASSWORD')
)
Other Considerations • If the one of the suggested uses for this is secrets, care must be taken to ensure any caching does not inadvertently store the values. • What should happen when the variable is unset or 'falsly' in the environment? Describe alternatives you've considered Alternatively, these fields could be made to support environment variable interpolation by default. e.g.
docker_image(version='${VERSION}')
. While this would also work, it would require Pants developers to second-guess/dictate where environment variables might be used and increase the complexity. pantsbuild/pants
u