I have git server running on Gitolite, under "git" system user. I added to ~/.profile of git user: export STAGE_PATH="/srv/http/stage"
, as you can guess, I want to automagically put website from repo on stage when pushing changes. However it seems that variable STAGE_PATH is unavailable to me in post-receive hook. Is it normal? Is there a way to access environment variables from post-receive hook?
The git hook will not login the git
user to a shell and therefore things export
ed in the usual places won't be available. In fact only a rather small number of environment variables will be set when the hook is executed.
You may check this out by inserting for line in $(printenv); do echo $line; done
) in your hook. Of course only for debugging purposes.
How about adding . ~git/.profile at the top of your post-receive hook script (assuming it's sh).
It's unclear exactly what you want, though. You either want:
1) just to push to an external spot, and don't care about commonality between repos. In which case, why do you need an environment variable from somewhere else? Why not put the final location inside the post-receive hook script itself?
2) You want to have some external variable that controls the root of where you're going to push a lot of different repos to, and it would be better to code that location into a single variable if you ever need to change it. If that's the case, what you're doing above makes sense. But you don't, necessarily, need to do it in the .profile in the first place. Clearly git is cleaning the environment for you before running your script. So, you should instead source an external file instead that contains your parameters (though I'd argue against using .profile for this).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With