3 answers

1 accepted

You can do this with ScriptRunner for Bitbucket Server. You need to use the pre-receive hook "protect git references" . You can enable this by going to Admin -> Pre-receive hooks -> Protect git references. The documentation for that is here.

You'll need to use a condition like the following on that hook to exclude the binary file extensions:

pathsMatch('regex:.*\\.jar$|.*\\.exe$')

The example above shows you how to do it for jar and exe files.

You can also use the "restrict file size" hook here to block files based on file size, which you may find useful to combine with the rule above.

Alternatively you can use the following as a custom pre-receive hook, but it may not catch every case. You should try it and see if it works for you: