In this page
Administrator guide
Step 1: Connect your Bitbucket workspace to your Jira site
Step 2: Enable custom merge checks for the workspace
Step 3: Add the merge check to a repository
Step 4: Add a commit policy to the repository
User guide
Step 1: View the merge check
Step 2: Resolve violations
Get started with commit policies
This page has two main sections:
- The Administrator Guide covers the essential setup steps an admin needs to complete before users can start using the app.
- The User Guide provides developers with simple, step-by-step instructions on the app's key features.
Take a few minutes to go through these guides - they'll help you get up and running smoothly! 🙂
Administrator guide
Don't worry if this guide looks long or complicated - it's really not! Most of these steps only need to be done once, usually when you're just getting started.
Note: different steps may require different permissions, which will be clearly indicated where needed.
Step 1: Connect your Bitbucket workspace to your Jira site
(estimate: 2 min, requires Jira administrator permission)
The VCS connection (a secure connection between Jira and your Version Control System) only needs to be set up once when you're getting started. You'll only need to do it again if you add another Jira site later on.
Steps:
- Go to your Jira site.
- Install the Better Commit Policy for Jira app to the Jira site (if it is not already).
- On the Jira interface, go to Apps (in the left-bar) → Better Commit Policy.
- Click Connect a VCS workspace now (on the top).
-
Create the VCS connection:
- Click Add VCS connection.
- Select Bitbucket as VCS hosting service.
- Enter your Bitbucket workspace URL.
- Click Save.
- Click the workspace URL in the table. (Bitbucket opens in a new browser tab, but keep Jira open, as well.)
- ✓ VCS connection created!
Step 2: Enable custom merge checks for the workspace
(estimate: 30 sec, requires Bitbucket administrator permission)
A Bitbucket admin must enable custom merge checks for the entire workspace. Note that if there is at least one repository in the workspace using custom merge checks, you can safely skip this step, as it's already done.
Steps:
- Click the browser tab that shows your Bitbucket workspace.
- Go to Workspace settings (cog icon "⚙" in the top right) → Custom merge checks.
- Click Enable. (If you can't see the button, it is already enabled.)
- ✓ Custom merge checks enabled!
Step 3: Add the merge check to a repository
(estimate: 30 sec, requires repository administrator permission)
A repository admin must enable the custom merge check in a specific repository to check if pull requests targeted to that repository comply with the commit policy.
Steps:
- Go to the repository → Repository settings (cog icon "⚙" in the left-bar) → Custom merge checks.
- Click Add check at "Better Commit Policy Connector for Bitbucket".
- Select the "Commit policy satisfied" check.
- Select "All branches".
- Check "Required". (It is a Bitbucket Premium-only feature. On other plans, skip it.)
- Save it.
- ✓ Merge check added!
Step 4: Add a commit policy to the repository
(estimate: 3 min, requires repository write permission)
You're about to add a starter policy that ensures each commit message and pull request title includes a valid Jira work item key, and that pull request descriptions aren't left empty. This helps keep every change clearly linked to its Jira work item.
Steps:
-
Find your VCS connection ID (you'll need this later):
- Go back to your Jira site (should still be open in another tab).
- On the Jira interface, go to Apps (in the left-bar) → Better Commit Policy.
- In the Connected VCS workspaces box, find the Bitbucket workspace.
- Click the icon to copy the connection ID to the clipboard.
- Close the tab.
-
Add the policy configuration file in Bitbucket:
- In the repository, open Source (in another browser tab).
- Click the "..." button → Add file.
- Enter .commitpolicy.yml as filename.
-
Copy this to the file content (but don't commit it yet!):
commit-policy: name: "FOO commit policy" vcs-connection: id: "..." commit: rejection-message: "Commit messages must be a 5+ chars and start with a FOO work item key!" message: pattern: (?s)FOO-\d+ [A-Z0-9](\S|\S\s*){4,} work-item: jql: 'project=FOO and statusCategory="In Progress" and assignee="$commit.author"' count: "1+" non-matching: reject pull-request: rejection-message: "Pull request titles must be 5+ chars and start with a FOO work item key." title: pattern: (?s)FOO-\d+ [A-Z0-9](\S|\S\s*){4,} work-item: jql: 'project=FOO and statusCategory="In Progress" and assignee="$pull-request.author"' count: "1+" non-matching: reject description: pattern: (?:\S|\S\s*){9,}
- Throughout the file, replace "FOO" with the actual Jira project key associated with the code in the repository.
- At line 4, replace "..." with the VCS connection ID with the value you just copied to your clipboard. (Be sure to preserve the brackets!)
- Commit it.
- Close the tab.
- In the repository, open Commit policy.
- The Commit policy screen will display the parameters. (In case of validation errors, see the troubleshooting guide).
- ✓ Commit policy successfully added!
🎉 The app is ready to use! Follow the User Guide to get familiar with the features.
User guide
Once the commit policy is set up using the Administrator Guide, try out the merge checks.
Step 1: View the merge check
Merge checks make sure pull requests follow the commit policy. You can view the results right on the pull request screen.
Steps:
- Go to your Bitbucket workspace.
- Go to any repository where the commit policy was activated.
- Go to Pull requests, and click any open pull request.
- Look at the Commit policy section in the right-bar.
- If the pull request meets all the commit policy requirements, you'll see "Satisfied". Otherwise, it will show "N violations".
- ✓ The merge check definitely works!
Step 2: Resolve violations
To learn how to resolve violations, start by finding a pull request that shows "N violations". We'll use it as our example.
Steps:
- View the violation list in the Commit policy section in the right-bar.
-
For each violation:
-
Make the change needed to resolve it:
- The pull request title is missing the work item key? → Make sure to add one!
- The pull request description is empty? → Write it!
- The work item is not assigned to you? → Update the work item (or choose another)!
- ... and so on.
-
Re-run the merge check:
- If the violation was related to a commit → Push the fixed commit to the source branch! The merge check will re-run automatically.
-
If the violation was related to anything else →
Click the icon next to the "Commit policy satisfied" check.
(If the icon isn't available, click the pull request Approve button at the top, then click Unapprove to undo it. This workaround triggers a merge check re-run. It's needed because Bitbucket doesn't always show the icon when expected.)
-
Make the change needed to resolve it:
- Repeat these steps until the check status shows "Satisfied."
- ✓ Your pull request is perfect!
🎉 Congratulations! You now know how to use commit policies to keep your pull requests clean, consistent, and high quality.
Questions?
Ask us any time.