How do I trigger scripts on a merge or when a branch is deleted?
"This is great, but I want to run a command/script when a branch is removed, how can I have jenkins run a command when a branch is removed?"


  You will need to use a webhook for this, I use the following
  settings in Github:





  Bitbucket only supports the following webhooks:


 

"Is there a way to have Jenkins trigger a job before it removes the branch?"


  Not that I can see, but in Github you can create a custom label and
  trigger a job via a webhook when the label is added to a branch.