Hook Bitbucket with Jenkins
Configuring Jenkins
- Make sure our Configure Global Security setting is fine
- Entry our Jenkins project's Configure
- Check Trigger builds remotely
- Type the random text into Authentication Token
- Check Build when a change is pushed to Bitbucket
Expose the local server to the internet
ngrok allows us to expose a web server running on our local machine to the internet. Just tell ngrok what port our web server is listening on.
- Download ngrok for Linux 64-Bit version
ngrok-stable-linux-amd64.zip
- Unzip it to
~/
cd ~/
./ngrok help
- Expose a Jenkins server on port 8080 of our local machine to the internet.
ngrok http 8080
When we start ngrok, it will display the public URL of Jenkins. We can use it to instead of private IP http://localhost:8080
.
ngrok by @inconshreveable
Tunnel Status online
Version 2.0.25/2.1.1
Region United States (us)
Web Interface http://127.0.0.1:4040
Forwarding http://86e883ff.ngrok.io -> localhost:8080
Forwarding https:///86e883ff.ngrok.io -> localhost:8080
Connnections ttl opn rt1 rt5 p50 p90
0 0 0.00 0.00 0.00 0.00
Configuring Bitbucket
- Entry the Settings page of Bitbucket project
- Entry the Webhooks sub-page
- Press Add webhooks button
- Type any Title we like
- Type the URL of Jenkins project
It should be
http://USER_ID:API_TOKEN@JENKINS_URL/job/JENKINS_PROJECT_NAME/build?token=TOKEN_NAME
USER_ID: find it in Jenkins -> People page.
API_TOKEN: select the user in People page and find it at Configure page.
JENKINS_URL: need to use public IP address to instead of
http://localhost:8080
JENKINS_PROJECT_NAME
AUTH_TOKEN: Entry the Jenkins project -> Configure, find Authentication token at Build Triggers.
- Check Active of Status
- Select Triggers with Repository push
- Save it
Test the auto build trigger
- Commit the source to Bitbucket
- ngrok will display the state on Terminal
HTTP Requests ------------- POST /job/JenkinsTest/build 201 Created GET /static/cbf1fb65/images/top-sticker-bottom-edge.png 200 OK GET /static/cbf1fb65/favicon.ico 200 OK
- Jenkins will display the progress bar at Build Queue and Build History