1. Sebastian Sebastian
  2. scm-manager
  3. Issues

Issues

Issue #155 resolved

Environment in external Mercurial hooks

Roman Tekhov
created an issue

The repository has some external changegroup hooks. These hooks rely on some environment variables, e.g., JAVA_HOME defined for the user that runs SCM-manager. But these variables are not present in the environment during hook execution in case the push is done via HTTP (i.e., via SCM-Manager). Here is a minimal example to illustrate the problem:

In repository .hg/hgrc I have {{{ [hooks] changegroup.scm = python:scmhooks.callback pretxnchangegroup.scm = python:scmhooks.callback

changegroup.log = echo "JAVA_HOME: $JAVA_HOME" }}}

If I push localy from another repository located on the same server then everything works as expected: {{{ hg push /repo/hg/test --config hooks.changegroup.scm="" --config hooks.pretxnchangegroup.scm="" pushing to /repo/hg/test searching for changes adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files JAVA_HOME: /usr/java/latest }}}

So JAVA_HOME is in the environment and therefore printed (I've disabled SCM system hooks here). But if I push from remote location via HTTPS then I get: {{{ hg push pushing to https://repo.webmedia.eu/hg/test searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files remote: JAVA_HOME: }}}

So the environment doesn't include such variable. And if I print the output of the "env" command in a hook then the output is also quite different.

In the first case I was logged in as the same user that SCM-manager is being run as.

Does SCM-manager create some kind of sandbox execution environment when running hooks?

Some installation details:

OS is CentOS 6.2.

SCM-manager version is 1.14.

SCM-manager runs in the background using this approach: https://groups.google.com/forum/#!topic/scmmanager/-wNjenUbl0Q.

JAVA_HOME is defined in ~/.bash_profile. Declaring it in /etc/init.d/scmserver or bin/scm-server doesn't have effect.

Comments (7)

  1. Sebastian Sebastian repo owner
    • changed status to open

    SCM-Manager executes the hooks with the environment of the main process. You could check the environment of the main process with the following command:

    cat /proc/<pid>/environ
    

    Or more formatted:

    cat /proc/<pid>/environ  | perl -pne '$a=chr(0);s/$a/\n/g'
    

    You could see the complete environment in the logfile if you are enable the trace log:

    https://bitbucket.org/sdorra/scm-manager/wiki/faq

    I think the problem is that the main process does not know your JAVA_HOME variable.

  2. Roman Tekhov reporter

    SCM-manager has 2 processes which is right as you pointed out in this thread: https://groups.google.com/forum/#!topic/scmmanager/-wNjenUbl0Q. Both processes have normal environment of the corresponding user (I used the command you suggested).

    If I enable the trace logging level then I get output which includes environment without the needed variables, the same environment I get inside the hooks. I have attached the output.

  3. Log in to comment