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. Such a well-researched piece! It’s evident how much effort you’ve put in.

  2. Breaking down this topic so clearly was no small feat. Thanks for making it accessible.

  3. The words are like a melody, each post a new verse in a song I never want to end.

  4. The insights have added a lot of value to my understanding. Thanks for sharing.

  5. Every post of yours is a learning opportunity for me on the state of the country. Thanks for sharing the expertise.

  6. What a refreshing take on the state of the country. I completely agree with the points!

  7. Opened my eyes to new perspectives, and here I was thinking I’d seen it all.

  8. The insights are like a fine wine—rich, fulfilling, and leaving me wanting more.

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

  10. The writing style had me at hello. Engaged from start to finish, just like a perfect first date.

  11. I’m impressed by The ability to convey such nuanced ideas with clarity.

  12. You’ve articulated The points with such finesse. Truly a pleasure to read.

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

  14. The passion is infectious, or maybe that’s just my enthusiasm trying to match Thes. Inspiring, nonetheless!

  15. Making hard to understand topics accessible, you’re like the translator I never knew I needed.

  16. The research depth is so evident, I almost thought this was a thesis defense.

  17. The Writing is like a warm fireplace on a cold day, inviting me to settle in and stay awhile.

  18. The Writing is a constant source of inspiration and knowledge. Thank you!

  19. The Writing is like a secret garden, each post a path leading to new discoveries and delights.

  20. Charlotte Dog Park’s open fields are a dream for my fetch-loving pup—he’s obsessed.

  21. The post has broadened my perspective in ways I didn’t expect. Thank you for that.

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

  23. The post resonated with me on many levels, much like a perfectly tuned love song. Thanks for the harmony.

  24. The passion for this subject shines through The words. Inspiring!

  25. This is the most thorough piece I’ve read on the topic. The dedication to research is admirable.

  26. I appreciate the clarity and thoughtfulness you bring to this topic.

  27. The elegance of The prose is like a fine dance, each word stepping gracefully to the next.

  28. The Writing is a go-to resource for me. Thanks for all the hard work!

  29. Thank you, your article surprised me, there is such an excellent point of view. Thank you for sharing, I learned a lot.

  30. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.

Leave a Reply

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