Missing binaries during git hook

Viewed 25

Let's setup a post-receive hook for git like this:

#!/bin/sh
git --work-tree=/path/to/www --git-dir=/path/to/git/test_CI.git checkout -f

export PATH=$PATH:/usr/bin #(<- this export does not help much)
yarn build

The first line work well, but yarn build fails, because the hook doesn't know yarn at all. (Running yarn in my host-terminal works perfeclty, though. The host is running on Ubuntu 18.04. by the way.)

which yarn tells me the exact location of yarn:

/home/.../.nvm/versions/node/v12.18.3/bin/yarn

I can use this for the hook. But the path contains the current yarn versionnumber, which will cause other problems, once the systems gets updated.

Plus, nvm, or node or nuxt and so on won't be found next. So this is not a clever workaround.

How can you make all the things that you have access to in your teminal (not only yarn) available for the hook?

1 Answers
export PATH=$PATH:/usr/bin #(<- this export does not help much)

This adds /usr/bin, which should already be part of $PATH to begin with, so... it does not do much.

I would check, as seen in nvm-sh/nvm issue 355 if you can have ~/.nvm/current/ symlink (symbolic link), in order for the $PATH to remain constant, even when npm is updated.

Related