In this page
1 - How do the alternatives compare to Better Commit Policy for Bitbucket?
2 - Can I install commit hooks directly into the Bitbucket Server managed, server-side Git repositories?
FAQ
1 - How do the alternatives compare to Better Commit Policy for Bitbucket?
There are other Bitbucket apps existing with commit verification functionality. See the comparison table below.
Better Commit Policy for Bitbucket | Jira Hooks for Bitbucket | Yet Another Commit Checker | |
---|---|---|---|
Project-level and repository-level configuration | Yes | Yes | No (global and repository-level only) |
Shared configuration | Yes (reuse policies among projects and repositories) | No | No |
Flexibility | High (multiple per-branch or per-directory rules, multiple conditions combined with AND/OR) | Low | Low |
Commit-time verification (with local hooks) | Yes (super-fast!) | No | No |
Push-time verification (with Bitbucket hooks) | Yes | Yes | Yes |
Pull request verification (with Bitbucket merge checks) | Yes | Yes | No |
Tag verification | Tag name format, issue links | No | No |
Branch verification | Branch name format, issue links | Branch name format, issue links | Branch name format |
Commit message verification | Text format, issue links | Text format, issue links | Text format, issue links |
Commit file verification | File paths, issue links | No | No |
Commit author verification | Name, email, user account, Jira group membership | No | Name, email |
Verification completeness | Complete verification of all conditions on all changes | Verification stops at first failure | Verification stops at first failure |
Support for multiple linked Jira instances | Allows precisely selecting the Jira instance and the commit policy | ? | Repeats the verification in each linked Jira instance (may be inaccurate) |
Support | Supported | Supported | Supported by the user community |
2 - Can I install commit hooks directly into the Bitbucket Server managed, server-side Git repositories?
This section describes an alternative method to integrate Bitbucket Server with Jira. It takes a lower level approach, based on native Git hooks (instead of Bitbucket Server hooks). It should be used very rarely, in situations when you want more control or custom behavior. It works by adding actual Git hook scripts to the repositories managed by Bitbucket Server, without conflicting with the hook scripts dynamically generated by Bitbucket Server.
The idea is that we will use a Bitbucket Server hook type called External Pre Receive Hook, which can execute external commands on the server. We will configure this hook to execute the Python interpreter with the Better Commit Policy's hook script! That way the policy checker hook script becomes a natural part of the Bitbucket Server managed hooks.
Before starting the hook installation, we strongly suggest reading this section. It is about Git workflows in general, and about deciding which repositories you should install the hooks into.
Actual installation steps:
-
If it is not installed yet, install the External Hooks Plugin to Bitbucket Server.
It is free and it provides the hook type we're going to use.
If it is already installed, skip this step.
Installing the app requires administrator permissions to Bitbucket Server, and it is described in the Installation tab here. - Generate a hook script package for Git, the same way you'd do when using Git without Bitbucket Server.
- Extract the ZIP to some temporary directory.
- Because Bitbucket Server has its own hook script called pre-receive, we need to avoid the conflict: rename the file pre-receive to pre-receive.jcp in the temporary directory.
- Login to Bitbucket Server as administrator. Go to the Settings → Repository details page of the repository to which you want to install the hook script. The Location on disk field will show you the repository's directory in the server's filesystem.
- Go to that directory in the filesystem, and then to its hooks subdirectory. Move the files from the temporary directory to this directory.
- As instructed by the Hook Script Generator's guide (step 4), add the execution permission to pre-receive.jcp (not pre-receive!) and run pre-receive.jcp (not pre-receive!) in diagnostic mode to verify if it works.
-
Open pre-receive.jcp in a plain text editor and change this line (around line 28):
return not sys.argv[0].startswith('hooks')
to:return False
-
Go back to Bitbucket Server, to the Settings → Hooks page of the repository.
Enable the External Pre Receive Hook with the following parameters:
-
Executable: /usr/bin/python
This is the full path of the Python executable in your server which will be launched by this hook. If you mistype this, the hook will fail to execute Python. - Safe mode: leave it unchecked
-
Positional parameters: <YOUR_REPOSITORY_DIRECTORY>/hooks/pre-receive.jcp
This is the full path of the Better Commit Policy's hook script. Don't forget to enter the actual directory path to the <YOUR_REPOSITORY_DIRECTORY> placeholder. The final path should be similar to this: /srv/atlassian-bitbucket-data/shared/data/repositories/71/hooks/pre-receive.jcp. If you mistype this, Python will fail to find the script.
-
Executable: /usr/bin/python
- Do some testing by commiting changes that should be rejected (negative testing) or accepted (positive testing).
- Have a chocolate, coffee or beer - depending on the period of the day.
Questions?
Ask us any time.