This scheduled job will automatically send email notifications periodically based on a condition and email template. This is particularly useful if you want a daily summary of what has happened in Bitbucket.

You will just need to configure the interval and then provide a subject and an email template, as well as the email format (plain text or HTML) and a list of recipients.

List all public repositories

This example sends an email notification listing all the public repositories present in your Bitbucket Server instance.

The email format selected should be Plain text.

You can use the following code below in the Condition and Configuration section:


Unresolved directive in <stdin> - include::{projectdir}/bitbucket/src/test/resources/examples/docs/bitbucket/ListPublicRepos.groovy[tag=ex1]

As this is a condition the email will only be sent if there are public repositories in your Bitbucket instance.

  1. We find all public repositories
  2. For each public repository we build a string containing the project key and repository slug

  3. We use the config variable in the binding to store the content for use in the template below (see additional configuration section for details)

  4. The condition will evaluate to true if we have any private repositories and then the email will be sent

The subject template:


List of public repositories:

The body template:


These repositories are public, you should review them:

$publicReposContent

The result should look similar to the following:


These repositories are public, you should review them:

PROJECT_1/aPublicRepo
PROJECT_5/anotherPublicRepo

Additional Configuration in Emails

You may notice the syntax for getting content in the template is a bit clunky, as the template engine does not allow you to use the import keyword. Rather than doing this, you can pass in a config map to the bindings for both the subject and body templates. This is done in the Mail configuration section.

A useful example of a Mail configuration section that defines config variables for all pull requests that have been merged in the last 24 hours is:


Unresolved directive in <stdin> - include::{projectdir}/bitbucket/src/test/resources/examples/docs/bitbucket/PullRequestMergedSinceYesterday.groovy[tag=ex1]

You will have to change the projectKey and repoSlug variable above to match your own. The email format selected should be HTML.

The subject template:


Unresolved directive in <stdin> - include::{projectdir}/bitbucket/src/test/resources/templates/AllMergedPullRequests.template[tag=subject]

The body template:


Unresolved directive in <stdin> - include::{projectdir}/bitbucket/src/test/resources/templates/AllMergedPullRequests.template[tag=body]

As a result of that configuration, an email will be sent to the selected email addresses with a content similar to the following one:

Clicking on the links will take you to that pull request in Bitbucket.