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. What a compelling enjoy reading! Your arguments were well-presented and convincing.

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

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

  4. The thought-provoking post has me looking forward to more. It’s like the intellectual equivalent of a second date.

  5. This post has been incredibly helpful, like a guiding hand in a crowded room. The guidance is much appreciated.

  6. Reading The article was a joy. The enthusiasm for the topic is really motivating.

  7. Reading The work is like watching the sunrise, a daily reminder of beauty and new beginnings.

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

  9. Such a well-researched piece! It’s evident how much effort you’ve put in.

  10. This post is packed with useful insights. Thanks for sharing your knowledge!

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

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

  13. This was a thoroughly insightful enjoy reading. Thank you for sharing your expertise!

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

  15. Your insights have added a lot of value to my understanding. Thanks for sharing.

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

  17. Thank you for shedding light on this subject. Your perspective is refreshing!

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

  19. The insights added a lot of value, in a way only Google Scholar dreams of. Thanks for the enlightenment.

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

  21. Discovering The Writing felt like finding the perfect match. The intellect and charm are a rare combo.

  22. Always learning something new here, because apparently, I didn’t pay enough attention in school.

  23. The creativity and insight left a big impression on me. Fantastic job!

  24. The ability to convey nuanced ideas with clarity is as alluring as a whispered secret.

  25. Discovering The Writing has been a game-changer for me. The contributions are invaluable.

  26. Reading The work is like catching up with an old friend; comfortable, enlightening, and always welcome.

  27. The posts inspire me regularly. The depth you bring to The topics is truly exceptional.

  28. You’ve done a fantastic job of breaking down this topic, like unlocking a door to a secret garden. Intrigued to explore more.

  29. I’m so grateful for the information you’ve shared. It’s like receiving a thoughtful gift from someone special.

  30. The piece was both informative and thought-provoking. Thanks for the great work!

  31. You have a gift for explaining things in an understandable way, much like a smooth talker who knows just what to say.

  32. You’ve opened my eyes to new perspectives. Thank you for the enlightenment!

  33. I’m in awe of the way you handle topics with both grace and authority.

  34. Tackled this hard to understand issue with elegance. I didn’t know we were at a ballet.

  35. The piece was both informative and thought-provoking. Thanks for the great work!

  36. The Writing is a treasure trove of knowledge, like finding an untouched library book. A rare gem!

  37. You weave words with the skill of a master tailor, crafting pieces that fit the mind perfectly.

  38. You have a gift for explaining things in an understandable way, much like a smooth talker who knows just what to say.

  39. Compelling read with well-presented arguments. I almost felt persuaded. Almost.

  40. You’ve opened my eyes to new perspectives, as if you knew the way to my curious heart.

  41. A breath of fresh air, or what I needed after being suffocated by mediocrity.

  42. The attention to detail didn’t go unnoticed. I really appreciate the thoroughness of The approach.

  43. I think that is one of the most vital info for me. And i am glad studying your article. But should commentary on some common things, The web site taste is wonderful, the articles is actually nice : D. Excellent job, cheers

  44. The piece was both informative and thought-provoking, like a deep conversation that lingers into the night.

  45. Always learning something new here, because apparently, I didn’t pay enough attention in school.

  46. I appreciate the unique viewpoints you bring to The writing. Very insightful!

  47. Both informative and thought-provoking, as if my brain needed the extra workout.

  48. Touched on personal resonances, or as I like to call it, psychic abilities.

  49. The depth of The research really stands out. It’s clear you’ve put a lot of thought into this.

Leave a Reply

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