5

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.

1 Answer 1

4

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).

5
  • Interesting +1. How do you clean up does branch builds?
    – 030
    Commented Apr 26, 2018 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
    Commented Apr 26, 2018 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
    Commented Apr 26, 2018 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
    Commented Apr 26, 2018 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
    Commented Apr 26, 2018 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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