Closed JorisVanEijden closed 10 years ago
Hmm, I've never tested it on merge, actually.
I've definitely take a look.
Oops, never mind. Pushes were also not working because I set the exe wrong. Everything works fine.
Only thing is that some additional logging if the process cannot be run would be nice.
I had: exe: "/var/app/someshellscript" params: "" This produced no errors and no logging and no effect. Changing it to: exe: "/bin/sh /var/app/someshellscript" params: "" threw the IOException and produced a line in the log. But this actually worked: exe: "/bin/sh" params: "/var/app/someshellscript"
Variant with exe: "/var/app/someshellscript"
has not worked probably because of missing +x
flag on the someshellscript
.
As far as I can see in that case there is following error:
[INFO] [talledLocalContainer] 2014-08-05 11:23:06,395 ERROR [threadpool:thread-1] admin @VE9Q22x683x368x0 192.168.4.20 "POST /scm/project_1/rep_1.git/git-receive-pack HTTP/1.1" c.n.s.e.hook.ExternalPreReceiveHook Error running [/tmp/some_shell_script, ] in /root/atlassian-external-hooks/target/stash/home/shared/data/repositories/1
...
[INFO] [talledLocalContainer] Caused by: java.io.IOException: error=13, Permission denied
At least I can see this error when I create non-executable file /tmp/some_shell_script
and then specify it as hook exe.
Actually, the script is executable and runs fine when I su to the atlstash user and run it manually. Looks like there is something different between the stash java process calling the script and the stash user running is from the shell. Debug code at the top of my script gets executed. The rest fails silently. I'll go work on that with more debugging.
*Edit: got it. It was not to do with the exe and params after all. I was using sudo from my script. That silently fails when no TTY is present. That's why it worked from the shell and not from java. I added a !requiretty to my stash user in the sudoers file and now everything works ok. Thanks for thinking along.
You're welcome. Anyway, you found everything by yourself :cat:
The astlassian developer documentation states that "Post-receive hooks are invoked after a push or merge has taken place" but my external hook is only called on pushes, not when merging pull-requests on stash.
Someone else has run into the same issue: https://answers.atlassian.com/questions/287561/stash-plugin-for-that-triggers-a-remote-script-when-the-pull-request-is-merged And he has posted sample code that should not have the issue.
However, I fail to understand why his code should work on merges and the code of external-hooks would not?