5

Is there any way to send an email when someone pushes one or more commits that modifies files inside a folder?

I have a folder with files that contain generic code that shouldn't be changed in most of the commits. But if someone pushes a change on those files, I would like to trigger an email/slack notification.

Is it possible to do with BitBucket server? maybe is there a plugin that allows me to do that?

Gaston K
  • 477
  • 1
  • 4
  • 12

1 Answers1

2

If you are talking about bitbucket.org, meaning a Git repository hosting server you don't have a direct access/control to, you need to setup a webhook

That webhook will call the web listener of your choice, which can inspect the push JSON payload, and fetch the new commits into a local repo.

From there, you can make a diff, and check if a specific directory content has changed.

And yes, as commented, a Jenkins server (that you control) can be used as a webhook listener, with the JENKINS/Generic Webhook Trigger Plugin.

The OP Gaston K mentions in the comments:

I'm using bitbucket server, which is basically the same but running on my end, I guess.

Then, if you have access to the server, you can setup a post-receive hook: see "Atlassian / BitBucket / Using repository hooks". You will use the Repository Hook Plugin Module, to define a hook of type "PostRepositoryHook"

You can then, using the Atlassian SDK, code a class which implements that type:

public class NotificationPostRepositoryHook implements PostRepositoryHook<RepositoryHookRequest> {

(see for instance Creating a New Plugin from Scratch to get started)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm using bitbucket server, which is basically the same but running on my end, I guess. What do you suggest in that case? Setting up a webhook as well? – Gaston K Jan 03 '19 at 06:51
  • @GastonK I have edited the answer to address your comment. – VonC Jan 03 '19 at 07:37