I'm missing something obvious here.

Is there no way to trigger a Jenkins scripted pipeline job via Bitbucket hook?

There's a bug out about it but it's been around for years with apparently no fix. Is the only way to make this work really to make an upstream trigger job that kicks off the pipeline? That seems insanely clunky.


If you just need generic post-receive hooks, you can just do a regular web hook and hit the build API endpoint. For instance, if the name of your Jenkins server is jenkins.example.com and the name of the Pipeline job to trigger is my_awesome_job, then you can fire off a POST request to https://jenkins.example.com/job/my_awesome_job/build. Depending on your security model, this request may or may not need to be authenticated and authorized. If you do need authentication and authorization, you can use HTTP Basic auth (unfortunately I haven't found a reasonable way to do keypair auth).

If you need to trigger builds on pull requests, then you'll need a plugin. I've been using the pull-request-notifier plugin for Bitbucket to trigger builds from Bitbucket and it's worked pretty well. It works especially well in combination with the Bitbucket Branch Source plugin for Jenkins, which automatically creates Jenkins jobs for every branch and open PR of every single repository in a Bitbucket project. The combination of these two plugins allows me to automatically trigger builds as soon as a PR is opened and prevent merging the PR until the build passes (this is a pretty common workflow so I figure it's worth mentioning even if you didn't explicitly ask about it).

  • Interesting +1. How do you clean up does branch builds? – 030 Apr 26 '18 at 17:57
  • The Bitbucket Branch Source plugin automatically cleans up stale branches. It has configurable parameters for this; for instance, I configured it to keep jobs for deleted branches and closed PRs for 30 days and then delete the job. – jayhendren Apr 26 '18 at 20:07
  • And what about the resource management in Jenkins? How do you ensure that there are enough executors? I can imagine that there will be a lot of extra load on Jenkins. – 030 Apr 26 '18 at 20:10
  • Regarding the Pull Request Notifier for Bitbucket Will it work for BitbucketCloud as well? Does it cost money? If unavailable, will the bb b source plugin for jenkins still work? – 030 Apr 26 '18 at 20:11
  • 1
    It does not cost money. I use Bitbucket Server, not cloud, so I'm not sure about the compatibility there. However, I do know that the Bitbucket Branch Source plugin for Jenkins can automatically set up webhooks for Bitbucket cloud, so I don't think you even need the pull-request-notifier plugin for Bitbucket at all. – jayhendren Apr 26 '18 at 23:37

What about using the bitbucket plugin? https://wiki.jenkins.io/display/JENKINS/BitBucket+Plugin

Another option could be using the Jenkins API. https://wiki.jenkins.io/display/JENKINS/Generic+Webhook+Trigger+Plugin This means that the bitbucket API has to be investigated as well probably.

Or one could investigate the bitbucket plugin and fix it yourself or file/find the issue tracker and add a comment to great more awareness.

What about using multiple Jenkins jobs that each have one responsibility (Do one thing and do it well) and that trigger each other?

  • We have that installed, yeah. Our hook kicks off an identically configured freestyle job just fine, but doesn't trigger the pipeline one. I'm hoping someone has a less hacky way to make it work than triggering the pipeline job via an upstream freestyle one. – Alex Apr 25 '18 at 18:07
  • Is it bad to use a freestyle job and subsequently call the pipeline job? – 030 Apr 25 '18 at 18:42
  • Bad? Maybe not. But clunky, and more overhead than you'd hope was needed. I just can't believe there isn't a better solution. – Alex Apr 25 '18 at 18:49
  • On the other hand, one could also see it as do one thing and do it well. Putting all responsibilities in one job could also have cons. – 030 Apr 25 '18 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.