We always set some variables that are available during build:
You could, during build, read those variables and do “anything” with them - including make a function output their values (note that the variables aren’t available directly in functions - you’d have to interpolate the values during build). But, you could also create a static file with that information to keep things simpler, instead, since you’re already interpolating values programatically
This article talks a bit more about “how to use variables during build”: [Support Guide] Using environment variables on Netlify correctly