In today’s digital age, integration between various systems is crucial. There are instances when you might need your Jenkins server to communicate with external services on the internet, like when you want Jenkins to be triggered via a webhook from your version control system. If Jenkins is hosted locally, exposing it to the internet can be a challenge. Fortunately, tools like Ngrok come to the rescue. Here’s a guide on how to use Ngrok to expose your local Jenkins server to the world.

What is Ngrok?

Ngrok is a powerful tool that provides a secure tunnel from a public endpoint to a locally running network service. It exposes local servers behind NATs and firewalls to the public internet, making the development and testing process smoother and more integrated.

Setting up Ngrok for Jenkins

  1. Account Creation:
    • Go to ngrok.com.
    • If you don’t have an account, click on the “sign up” button and follow the registration process. If you’re already registered, simply log in.
  2. Downloading Ngrok:
    • Ngrok offers downloads for various operating systems. Hover over the link for your operating system (we’ll use Linux for this example) to see the download URL. Copy this URL for later use.
  3. Setting Up on Your Jenkins Server:
    • On your Jenkins server terminal, first install wget and unzip with the command: sudo apt install wget unzip.
    • Download Ngrok using: wget [Paste the ngrok download link here].
    • Unzip the downloaded file with the command: unzip [name_of_downloaded_file].
    • (Optional) Remove the zip file to save space with the command: rm [name_of_zip_file].
    • Move the Ngrok executable to the user bin directory using: sudo cp ngrok /usr/bin/.
  4. Configuring Ngrok:
    • Run the command ngrok to ensure the setup is correct. If you see Ngrok options displayed, the setup was successful.
    • Navigate to your Ngrok account dashboard and locate your auth token. Copy this token.
    • Back in your Jenkins server terminal, enter the command: ngrok authtoken [Paste the token here].
  5. Exposing Jenkins to the Internet:
    • Initiate Ngrok with the command: ngrok http 8080. (For Jenkins, the default port is 8080, but if you were exposing a different server, ensure you specify the right port).
    • Ngrok will then provide you with both HTTP and HTTPS URLs pointing to port 8080 of your local Jenkins server.
    • Copy any of the provided URLs and paste it into your browser. This will redirect you to your Jenkins instance where you can log in with your admin credentials.

Final Words

With the above steps completed, your local Jenkins server is now accessible from anywhere via the provided Ngrok URL. Remember, this method can be utilized for exposing not just Jenkins, but any local server. Just make sure to expose the right ports.