Git hook scripts are not executing

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Server と Data Center のみ - この記事は、サーバーおよびデータセンター プラットフォームのアトラシアン製品にのみ適用されます。

Bitbucket Server relies on hook scripts that are installed into each repository (and managed by the system) to provide change information that, in turn, allows it to index JIRA issues, update pull requests and check branch permissions, for instance.

If the hooks are not installed correctly or are damaged, these required callbacks do not happen and the functionality associated with them fails.

問題

When git hooks are not executing, Bitbucket Server does not detect changes to a repository and as a consequence:

  • Newly created repositories stay stuck in the 'empty repository' screen after changes have been pushed to the repository.
  • Branch permissions are not applied.
  • JIRA issue keys are not detected in pushed commits. As a result, no JIRA issue links are displayed for the commits and the commits do not show up on the JIRA issue.
  • Fork synchronisation is not triggered.
  • Caches are not cleared and cloning a repository can return stale data.

原因とソリューション

The git callback hooks are not installed correctly or are damaged, these required callbacks do not happen and the functionality associated with them fails.

Hook Scripts are Missing

In versions of Bitbucket prior to 4.11, the hook scripts will be named 20_stash_callback, not 20_bitbucket_callback. Both names will be accepted by Bitbucket and renaming the scripts is not necessary!

Bitbucket Server requires certain Git hooks to be installed into each repository for it to function correctly. But in this case many of the repositories are 'corrupt'. The following snippet from the application-properties/application.xml file, produced by the Support Tools Plugin, is an example of the files that need to be installed. If these entries are missing, hooks will not be run.


<git-hooks>
        <hook>
          <name>pre-receive</name>
          <size>430 B</size>
          <executable>true</executable>
          <callbacks>
            <callback>
              <name>20_bitbucket_callback</name>
              <size>416 B</size>
              <executable>true</executable>
            </callback>
          </callbacks>
        </hook>
        <hook>
          <name>post-receive</name>
          <size>432 B</size>
          <executable>true</executable>
          <callbacks>
            <callback>
              <name>20_bitbucket_callback</name>
              <size>418 B</size>
              <executable>true</executable>
            </callback>
          </callbacks>
        </hook>
      </git-hooks>


RESOLUTION

Affected repositories can be fixed by copying the 4 missing scripts - post-receive, post-receive.d/20_bitbucket_callback, pre-receive and pre-receive.d/20_bitbucket_callback - into the repository under <BITBUCKET_HOME>/data/repositories/<Repo_ID>/hooks directory. Ensure the scripts are executable after they are copied. To identify which repository ID maps to your affected repository, refer to this guide.

Hook Scripts are not Executable

Even if the required hook scripts are installed, they can only be run if they are executable. This can be checked with the same application-properties/application.xml, generated by the Support Tools Plugin, by looking for lines like the following. Notice that isExecutable shows false for the scripts.

        <hook>
          <name>pre-receive</name>
          <size>430 B</size>
          <executable>false</executable>
          <callbacks>
            <callback>
              <name>20_bitbucket_callback</name>
              <size>416 B</size>
              <executable>false</executable>
            </callback>
          </callbacks>
        </hook>


RESOLUTION

  1. Affected repositories can be fixed by running chmod u+x on non-executable scripts. The exact path to each script is included in the XML.
  2. It is also common that the mount line for the Bitbucket Server volume does not have an executable flag. You should mount the partition with an executable flag. Example of a wrong mount:

$ mount | grep bitbucket
/dev/sdb1 /bitbucket ext4 rw,user 0 0

      A demonstration with a temporary ramdisk:

      A) Mounting without exec, giving a script exec permissions and trying to execute it - this won't work

> mkdir /tmp/ramdisk && sudo mount -t tmpfs -o rw,user tmpfs /tmp/ramdisk/
> echo "echo no exec' >> /tmp/ramdisk/ && chmod a+x /tmp/ramdisk/test
> /tmp/ramdisk/test
-bash: /tmp/ramdisk/test: Permission denied
> sudo umount /tmp/ramdisk/

      B) Mounting with exec, giving a script exec permissions and trying to execute it - this will work:

> mkdir /tmp/ramdisk && sudo mount -t tmpfs -o rw,user,exec tmpfs /tmp/ramdisk/
> echo "echo hello' >> /tmp/ramdisk/ && chmod a+x /tmp/ramdisk/test
> /tmp/ramdisk/test
hello
> sudo umount /tmp/ramdisk/
説明Bitbucket Server relies on hook scripts that are installed into each repository (and managed by the system) to provide change information that, in turn, allows it to index JIRA issues, update pull requests and check branch permissions, for instance. If the hooks are not installed correctly, or are damaged, these required callbacks do not happen and the functionality associated with them fails.


<git-hooks>
<hook>
<name>pre-receive</name>
<size>430 B</size>
<executable>true</executable>
<callbacks>
<callback>
<name>20_bitbucket_callback</name>
<size>416 B</size>
<executable>true</executable>
</callback>
</callbacks>
</hook>
<hook>
<name>post-receive</name>
<size>432 B</size>
<executable>true</executable>
<callbacks>
<callback>
<name>20_bitbucket_callback</name>
<size>418 B</size>
<executable>true</executable>
</callback>
</callbacks>
</hook>
</git-hooks>

最終更新日 2020 年 1 月 9 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.