A proxy that transforms Bitbucket webhook calls to a format that can trigger Jenkins parameterized builds.
- Bitbucket's webhook can only post JSON requests
- Change details (e.g. commit author, commit SHA, etc) of Bitbucket's webhook calls is located in the request body
- Jenkins' remotely triggered jobs (via webhook) cannot inspect the request body
- We need commit details from webhook to be available as build parameters in Jenkins jobs
- so we can checkout and build only those specific commits
There are two methods to run it.
It requires Python 2.7 and preferably isolated environment (e.g. virtualenv).
git clone https://github.com/akhyrul/jenkins-bitbucket-webhook-proxy webhook-proxy
cd webhook-proxy
pip install -r requirements.txt
python app.py
docker run -p 5000:5000 -i -t akhy/jenkins-bitbucket-webhook-proxy
- Open up your job configuration
- Check "This build is parameterized" and add a string parameter named "GIT_HASH". This parameter will be provided by our proxy app from Bitbucket webhook.
- In build triggers section check Trigger builds remotely and enter any random authentication token. This token will be used in the next Bitbucket configuration.
- Make sure in source code management section, you choose Git. Set branches to build to ${GIT_HASH}
Create a webhook with repository push trigger and this URL template:
http://myproxy.tld:5000/build?jenkins=https://jenkins.mycompany.com:8080**&job=**job**&token=**token
- myproxy.tld:5000 is where your proxy is listening
- jenkins query param is your Jenkins URL
- job query param is the Jenkins job's name (see the URL when you're editing the job)
- token query param is the token you have set in the Jenkins job before
Note: Currently the proxy can only handle repository push trigger.
- Handle more Bitbucket webhook triggers
- Tests