After adding an "External Async Post Receive Hook", any push LOOPS ENDLESSLY Edited

Added:  Atlassian Bitbucket v4.14.4

From my own repos setting page:

<SERVER>/users/christopher.hahn/repos/hooktest/settings/hooks

this is the text from the hook config web-dialog:
===============================

External Async Post Receive Hook

Executable: basictest.sh
Path to executable to run.

Safe mode [X] Look for hooks only in safe dir

Hooks will be searched only in <stash-home-dir>/external-hooks/
===============================

 

The script:
/var/atlassian/bitbucket-home/external-hooks/basictest.sh
is a classic, off the net:
===============================

#!/bin/bash

(
echo "Script name: $0"
echo "Positional arguments: ${@}"
echo "STASH_USER_NAME: $STASH_USER_NAME"
echo "STASH_USER_EMAIL: $STASH_USER_EMAIL"
echo "STASH_REPO_NAME: $STASH_REPO_NAME"
echo "STASH_IS_ADMIN: $STASH_IS_ADMIN"
while read from_ref to_ref ref_name; do
echo "Ref update:"
echo " Old value: $from_ref"
echo " New value: $to_ref"
echo " Ref name: $ref_name"
echo " Diff:"
git show $from_ref..$to_ref | sed 's/^/ /'
done
) | tee -a /tmp/external-hooks-test.log

===============================

The script is 755 and runs fine from the command line.

BUT, when I push any change, the console loops over the same output:
===============================
$ git push newbranch
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/heads/newbranch
remote:
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/heads/newbranch
remote:
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/heads/newbranch
<SNIP>
remote:
remote: Create pull request for newbranch:
remote: https://XXXXX/users/christopher.hahn/repos/hooktest/compare/commits?sourceBranch=refs/heads/newbranch
remote:
Killed by signal 2.
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer
To ssh://git@XXXXX:7999/~christopher.hahn/hooktest.git
35734f5..8544dec newbranch -> newbranch
===============================

Has anyone else seen this?

 

2 answers

This widget could not be displayed.

I need to add that I reduced the script down to just:

#!/bin/sh
echo "IN SCRIPT"
exit 0

and reran my test. 

The result did not loop, but it just hung without returning:

$ gush master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 342 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
Killed by signal 2.
fatal: The remote end hung up unexpectedly
error: error in sideband demultiplexer

...check out that message when I killed the process...interesting!

More Data...just added as a comment on the related card:

I have queries on two different boards, the Atlassian Community and the Github site of the plugins creators.  No responses yet.

I am now testing using the "safe dir" and the simplest of scripts:

[stash@XXXXX 765]$ /var/atlassian/bitbucket-home/external-hooks/test.sh
IN SCRIPT: Test
[stash@XXXXX 765]$ cat !$
cat /var/atlassian/bitbucket-home/external-hooks/test.sh
#!/bin/sh

echo "IN SCRIPT: Test"
exit 0

Note the simplicity of the script.

The error seen in the log when one of these pushes hangs:

2017-10-06 08:28:48,520 ERROR [AtlassianEvent::thread-3] christopher.hahn @16MC444x508x1769362x0 fcszye X.X.X.X SSH - git-receive-pack '~christopher.hahn/hooktest.git' c.n.s.e.hook.ExternalPreReceiveHook Error running [/var/atlassian/bitbucket-home/external-hooks/test.sh, ] in /var/atlassian/bitbucket-home/shared/data/repositories/765
java.io.IOException: Broken pipe
2017-10-06 08:38:19,894 ERROR [AtlassianEvent::thread-3] christopher.C366x516x1773236x0 1visy70 X.X.X.X SSH - git-receive-pack '~christopher.hahn/hooktest.git' c.n.s.e.hook.ExternalPreReceiveHook Error running [/var/atlassian/bitbucket-home/external-hooks/test.sh, ] in /var/atlassian/bitbucket-home/shared/data/repositories/765
java.io.IOException: Stream closed
This widget could not be displayed.

I got my own answer: I had first tried to get this working using a script in the traditional location...the repos hook directory.

Well, I had left a copy of some version of my script down on the post-receive.d sub-directory.

What I was seeing that that "second script" being run, over and over and over.

The idea here is that one should just stay away from using hooks with Bamboo *unless* you are using a plugin to drive them.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,207 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you