<p>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 <code>jenkins.example.com</code> and the name of the Pipeline job to trigger is <code>my_awesome_job</code>, then you can fire off a POST request to <code>https://jenkins.example.com/job/my_awesome_job/build</code>.  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).</p>

<p>If you need to trigger builds on pull requests, then you'll need a plugin. I've been using the <a href="https://marketplace.atlassian.com/plugins/se.bjurr.prnfs.pull-request-notifier-for-stash/server/overview" rel="nofollow noreferrer">pull-request-notifier plugin for Bitbucket</a> to trigger builds from Bitbucket and it's worked pretty well.  It works especially well in combination with the <a href="https://plugins.jenkins.io/cloudbees-bitbucket-branch-source" rel="nofollow noreferrer">Bitbucket Branch Source plugin for Jenkins</a>, 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).</p>

CC BY-SA 3.0
2018-04-26T17:57:48.790Z
Interesting +1. How do you clean up does branch builds?
030
CC BY-SA 3.0
2018-04-26T20:07:05.920Z
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
CC BY-SA 3.0
2018-04-26T20:10:10.623Z
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
CC BY-SA 3.0
2018-04-26T20:11:36.023Z
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
CC BY-SA 3.0
2018-04-26T23:37:38.207Z
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
CC BY-SA 3.0
2018-04-26T17:26:47.503Z
2018-04-26T17:26:47.503Z
jayhendren
<p>I'm missing something obvious here. </p>

<p>Is there no way to trigger a Jenkins scripted pipeline job via Bitbucket hook? </p>

<p>There's <a href="https://issues.jenkins-ci.org/browse/JENKINS-38447" rel="nofollow noreferrer">a bug out</a> 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.</p>

<jenkins><jenkins-pipeline><bitbucket><bcbsn>
Trigger jenkins pipeline job with Bitbucket hook
Alex
# Trigger jenkins pipeline job with Bitbucket hook

(Asked by: username_0 on 2018-04-25)

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](https://issues.jenkins-ci.org/browse/JENKINS-38447) 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.

**Tags:** jenkins, jenkins-pipeline, bitbucket, bcbsn


---

## 1 answers

### Answer by username_1 on 2018-04-26. Score: 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](https://marketplace.atlassian.com/plugins/se.bjurr.prnfs.pull-request-notifier-for-stash/server/overview) 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](https://plugins.jenkins.io/cloudbees-bitbucket-branch-source), 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).

> **Comments:**
> **username_2**: Interesting +1. How do you clean up does branch builds?  
> **username_1**: 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.  
> **username_2**: 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.  
> **username_2**: 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?  
> **username_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.  

---

