How to Point BitBucket Webhook to Jenkins on Localhost

If you want to host your Jenkins locally on your computer for testing, but are interested in leveraging BitBucket’s webhooks to point to your localhost, then you need to expose your computer to the outside world.  There are several ways to do this, but the easiest I have found is to use a tool called ngrok. If you do not have it installed already and are using a Mac, I would suggest that you install it with Homebrew. This post was inspired by some instructions found on  GitHub actually, as opposed to BitBucket.

[code language=”bash”]
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew cask install ngrok
[/code]

You are ready to run ngrok now to expose your localhost to the outside world now. In this situation, I am demonstrating an example of exposing my local Tomcat; however, one word of caution is that you may not want to expose the default 8080 port. Reasons for doing this including a poor mans security to limiting the inbound traffic you expose yourself to by doing this. In order to change your default port for Tomcat, follow the instructions here. An even better option would be to expose a secure link on https.

So, presuming you have installed ngrok and you have changed your default port to something non-standard, then you are ready to run the tool to expose your machine to the outside world:

[code language=”bash”]
$ ngrok http 8282
[/code]

Once you run this command, you will see the program run in the foreground (ideally you would want to run this in the background and/or as a service on reboot). In order to test that you have set things up successfully, we can test by simply going to one of the two provided URLs in a browser and in my case it would take you to the Apache Tomcat landing page; however, we really want to test that we can get a webhook to work. So, in order to do this, we could use BitBucket to trigger a webhook to a Jenkins instance deployed to my local Tomcat whenever I push a code change to BitBucket. Here is the configuration:

Jenkins BitBucket webhook

Jenkins BitBucket webhook

Now, we just need to make a code change and push it for testing. We can see both from ngrok and BitBucket that things worked by witnessing the HTTP 200 OKs.

ngrok running and it has successfully received two push requests from the webhook in BitBucket

ngrok running and it has successfully received two push requests from the webhook in BitBucket

Jenkins BitBucket Webhook Successful 200 OK requests log

Jenkins BitBucket Webhook Successful 200 OK requests log

By default, ngrok will only give you a session that last few a few hours at a time. Your options are to periodically restart your tunnel to expose your IP to the outside world, which also means needing to update your webook with the newest URL, or to sign up and register an authorization token: https://ngrok.com/upgrade. Even so, if you restart your command again (ie, reboot your machine or accidentally close the terminal that you used to launched the program), then you will still get a new URL.. As you may have guessed, the want you to pay them to get a static address.

230 Comments:

  1. You have brought up a very wonderful details, regards for the post.

  2. It’s going to be end of mine day, however before finish I am reading this impressive article to improve my know-how.

  3. I enjoy foregathering utile info, this post has got me even more info! .

  4. Your ability to distill complex concepts into readable content is admirable.

  5. Your article was a joy to read, and your enthusiasm is as infectious as your charm.

  6. Reading your work is like gazing at a masterpiece; every detail contributes to a breathtaking whole.

  7. Each post you write is like a letter I’ve been waiting for. Always delivered with care.

  8. Your content is like a treasure chest; every post uncovers gems of wisdom. X marks the spot here.

  9. Stumbling upon this article was the highlight of my day, much like catching a glimpse of a smile across the room.

  10. I adore meeting useful info, this post has got me even more info! .

  11. The way you articulate your thoughts is as refreshing as the first sip of coffee in the morning.

  12. The effort you’ve put into this post is evident and much appreciated. It’s clear you care deeply about your work.

  13. The depth you bring to your topics is like diving into a deep pool, refreshing and invigorating.

  14. This article is a perfect blend of informative and entertaining. Well done!

  15. Your passion for this subject shines through your words. Inspiring!

  16. Your creativity and intelligence shine through this post. Amazing job!

  17. A masterpiece of writing! You’ve covered all bases with elegance.

  18. Your blog is a constant source of inspiration and knowledge. Thank you!

  19. This is a brilliant piece of writing. You’ve nailed it perfectly!

  20. You’ve done a fantastic job of breaking down this topic. Thanks for the clarity!

  21. You have a unique perspective that I find incredibly valuable. Thank you for sharing.

  22. Your piece was both informative and thought-provoking. Thanks for the great work!

  23. I’m so grateful for the information you’ve shared. It’s been incredibly enlightening!

  24. Thank you for the hard work you put into this post. It’s much appreciated!

  25. I’m so grateful for the information you’ve shared. It’s been incredibly enlightening!

  26. This blog is a treasure trove of knowledge. Thank you for your contributions!

  27. This post was a breath of fresh air. Thank you for your unique insights!

  28. Your attention to detail is remarkable. I appreciate the thoroughness of your post.

  29. A masterpiece of writing! You’ve covered all bases with elegance.

  30. This post is a testament to your expertise and hard work. Thank you!

  31. I’m so grateful for the information you’ve shared. It’s been incredibly enlightening!

  32. Your post was a beacon of knowledge. Thank you for illuminating this subject.

  33. Thank you for consistently producing such high-quality content.

  34. You have a gift for explaining things in an understandable way. Thank you!

  35. You have a unique perspective that I find incredibly valuable. Thank you for sharing.

  36. Your ability to distill complex concepts into enjoy readingable content is admirable.

  37. I appreciate the unique viewpoints you bring to your writing. Very insightful!

  38. Your blog is a go-to resource for me. Thanks for all the hard work!

  39. Your dedication to quality content is evident. Keep up the great work!

  40. This blog is a treasure trove of knowledge. Thank you for your contributions!

  41. Your post has been incredibly helpful. Thank you for the guidance!

  42. This post was a breath of fresh air. Thank you for your unique insights!

  43. I appreciate the balance and fairness in your writing. Great job!

  44. Your piece was both informative and thought-provoking. Thanks for the great work!

  45. This piece was beautifully written and incredibly informative. Thank you for sharing!

  46. Your work is truly inspirational. I appreciate the depth you bring to your topics.

  47. A masterpiece of writing! You’ve covered all bases with elegance.

  48. I appreciate the unique viewpoints you bring to your writing. Very insightful!

  49. You have a unique perspective that I find incredibly valuable. Thank you for sharing.

  50. This piece was beautifully written and incredibly informative. Thank you for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *