Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT : Setting application environmental variables

In my GIT based project, I need to set several environmental variables which is required by build scripts and many other ant targets.

For now I have a shell script which will export variables but each time a user opens a new bash window, he will need to repeat the steps by executing the shell script in order to set the environmental variables.

Most of these variables are user machine/env dependent and these are evaluated on the fly by shell before being exported.

If there a way to make it more dynamic. I understand that GIT provides hook and one possibility is that I can use hook to call the shell when user checkouts to a branch.

But here again GIT persists the current working branch and if user goes to a new bash window he would continue to be in previously chosen branch and he might not call git checkout branch, and which eventually will not call env variables shell.

So what is the best of handle this ?

like image 862
user121618 Avatar asked Jul 10 '26 11:07

user121618


1 Answers

I usually version a build wrapper script used by the user for launching the build (in the current or in a new shell window)

That way, the environment variables are always set at each build.

Furthermore, by versioning that build.sh/build.bat wrapper script, you keep the knowledge of which options/environment variable your project needs in order to be built.
That wrapper script, if changed, is versioned and can be audited (git blame): you know who changed what and when.

like image 159
VonC Avatar answered Jul 13 '26 06:07

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!