How to find projects/repositories which have configured a particular plugin/hook
Platform Notice: Data Center Only - This article only applies to Atlassian apps on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
As a Bitbucket Server administrator you may have need to locate all projects or repositories currently using a particular plugin/hook on your Bitbucket Server instance.
This will work only when a Hook has been configured explicitly for a Repository. Since inherited hooks are applied for all repositories inside a project, they will not show up in the result.
Solution
The easiest way to get this data is from the REST API. Please see the rest endpoint /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/webhooks for more details. You can use name: to search for jenkins in the examples below.
Web hooks after Bitbucket 5.4
To find all hooks for a url for a repository. Replace '<SLUG>' with the SLUG name:
SELECT repo.name,
webhooks."URL"
FROM "AO_A0B856_WEBHOOK" as webhooks
join REPOSITORY as repo
ON cast(webhooks."SCOPE_ID" AS INT) = repo.id
WHERE repo.name = '<SLUG>';
To find hooks for all the repositories along with the project details:
SELECT prj.name AS "Project Name",
prj.project_key AS "Project Key",
repo.name AS "Repo Name",
repo.slug AS "Repository Slug",
webhooks."URL"
FROM "AO_A0B856_WEBHOOK" as webhooks
join REPOSITORY as repo ON cast(webhooks."SCOPE_ID" AS INT) = repo.id
join PROJECT as prj ON repo.project_id = prj.id;
Repository hooks
For example, for the Jenkins Webhook Plugin, you can run the following SQL query to get the names of all repositories that have the webhook enabled.
SELECT NAME
FROM repository
JOIN sta_repo_hook
ON repository.id = sta_repo_hook.repository_id
WHERE sta_repo_hook.hook_key LIKE '%jenkins%'
You can run the following SQL query to get the names of all projects that have the webhook enabled.
SELECT NAME
FROM project
JOIN sta_repo_hook
ON project.id = sta_repo_hook.project_id
WHERE sta_repo_hook.hook_key LIKE '%jenkins%'
The above queries were tested against a PostgreSQL database and may need to be altered to match the syntax of your specific database version/vendor.
Was this helpful?