Jenkins Download Mac

You may be working on a personal project. Maybe your company has a different CI/CD system from what you are used to or it’s hard to be onboarded with the CI/CD system. I’ve come up with a way to create your own personal Jenkins server and agent all in one macOS. The following diagram shows what I am envisioning.

Jul 21, 2018 Step 1: Open browser and enter URL Step 2: Scroll down the page until you see the Mac OS X section then click on it. This will start the download for a Mac installation package. Once the download is complete, click on the package to start the installation. Step 3: Accept the defaults from the installation wizard. (to exit out of nano after making the change, hit Ctrl+X, hit Y to save the changes, and hit Enter) Let’s start Jenkins and set it to run automatically when the system is rebooted: How To Download Jenkins On Mac High Sierra. The rest of the configuration will mostly be done in a browser on the local machine. The macOS installer for Jenkins is maintained outside the Jenkins project. Refer to documentation based on the version of Jenkins to be run.

This whole things can easily fit on a laptop or a desktop. Obviously the architecture could be applied to Windows and Linux as well. I have Mac as my main development machine, so I will use Mac as an example here.

Install Docker on Mac

Jenkins may NOT work with Java version 9.x. This was the first problem I struggled with. If you have the same problem, download JDK 8u152 and install it. NodeJS version 1.0 has adapted its code to the most recent Jenkins API (1.6xx). If also EnvInject is installed you will fall in JENKINS-26583 that corrupts setup of the nodejs installation bin folder into PATH environment. In this case consider if update or not or use an own build from this branch until the JENKINS-26583 will not be fixed.

Local

Installing Docker on macOS is very easy.

Download
  • First, download Docker for Mac from here.
  • (Double-)click the downloaded Docker.dmg file.
  • Drag and drop the Docker application file to /Applications directory.
  • Double-click Docker.app file in /Applications directory.
  • You may have to reboot your machine to get the daemon to work correctly.
  • Open Terminal.
  • Execute docker run -d -p 80:80 docker/getting-started
  • Once it’s successful, it means your Docker installation was successful.

One thing to note is that you don’t have to add your account to docker group so you don’t have to sudo for every docker command to execute and docker-compose is bundled with Docker.app on Mac, which is nicer than the installation process on Linux.

Jenkins Master

We will spin up the Jenkins master using docker-compose. Create a directory such as ~/jenkins.

Copy and paste the following contents in docker-compose.yaml file in ~/jenkins.

Execute the following command to create a network for your Docker containers.

After that, execute the following command from at ~/jenkins

When you see the output like the following, you have Jenkins up and running

At this point, you could hit the Jenkins master by navigating your browser to http://localhost:8080 but this is not what I want. I would like to have Dockerized NGINX in front of it and route the traffic to the Jenkins so that it is easy to implement SSL certs for it.

You can Ctrl+C to stop Jenkins and then…

to completely remove the container.

NGINX as Reverse Proxy

Jenkins

As the diagram indicates, my plan is to have NGINX accept HTTP(S) traffic and route the traffic to the Jenkins instance via the Docker’s virtual network.

Please follow the steps below.

Create a directory like ~/nginx

Copy and paste the following YAML to ~/nginx/docker-compose.yaml file and save the file.

Next, create ~/nginx/data directory. While you are there, let’s create conf.d directory.

Copy and paste the following contents to ~/nginx/data/nginx.conf file and save it.

Next, paste the following configuration to ~/nginx/conf.d/ssl.conf file.

SSL Support

Since I’m just planning to run this locally, there isn’t a need for SSL but I would like to implement this for a good practice. And you never know, you may want to create a Jenkins instance in a real environment eventually.

I am planning to make the URL https://jenkins.local

Place the following files for SSL support. If you need to know how to create self-signed cert, please take a look my previous article.

To summarize, here are the files you have to create for NGINX to work in the nginx root directory.

Download Jenkins On Local Machine

Next, let’s edit /etc/hosts file so that https://jenkins.local will resolve to your local NGINX.

Add the following line in the file.

Now navigate to ~/jenkins and execute the following command.

This starts the instance of Jenkins. Now navigate to ~/nginx and execute the following command.

This starts the instance of NGINX as a reverse proxy that routes the traffic to the containerized Jenkins.

Access Jenkins UI and Initial Configuration

Jenkins For Mac

If you open your browser, and navigate it to https://jenkins.local/ you should see the following screen.

Beware that if you try to get the Administrator password from /var/jenkins_home/secrets/initialAdminPassword, your host side does not have the file at that location. Instead, you should cat the file at the following location.

Once you get the admin password from the location, enter it to pass the initial screen to start the containerized Jenkins master.

Connect Jenkins Slave

If you take a look at the UI, you see that the Jenkins master has 2 executors by default. If you want your Mac to run builds, you can do so. Here are the steps.

Navigate to Manage Jenkins -> Manage Nodes and Clouds and then click New Node.

Jenkins

Enter mac for Node name and click Permanent Agent and then click OK.

And click Save on the next screen.

When you go back to Manage Nodes and Clouds, you will see the following screen.

Click mac (or whatever you created) and you will see the following screen.

How To Install Jenkins

You can definitely follow the instruction on the screen to connect your mac as a Jenkins slave. First download the agent.jar file from the same page and store it in ~/jenkins-slave directory.

Next execute the following command.

This writes the secret to the secret-file in the directory. And then try to execute the following command to get your mac connected to Jenkins master as a slave.

You would expect that this should be the last step but you would get an error like the following.

This means that Java does not trust the self signed SSL certificate you created. I blogged about this in the past, so please refer to this blog article to resolve this issue.

Once the SSL cert issue is resolved, it connects to Jenkins master and it’s ready like the image below.

Recap

Jenkins Download Mac

It took me a few nights to write up this article. To recap…

  • Dockerizing Jenkins master
  • Using NGINX as a reverse proxy
  • Implementing SSL cert
  • Jenkins slave

This give you an environment where you can manage your own Jenkins in Docker and do whatever you want!

Jenkins Download Macos

Related