Michael Bergeron

Seting up Jenkins in a TrueNAS (FreeNAS) jail

Update - There is actually a Jenkins jail in the TrueNAS / FreeNAS. So, give that one a shot, or continue using this tutorial to build a custom jail.

FreeBSD Jails

I’m running a TrueNAS 12.0 (nee FreeNAS) instance on a computer and home, and I wanted to setup a Jenkins instance to automate creation of a few things. (More on that later) I found a couple of guides, but things seemed out of date, so I decided to provide a brief quickstart.

If you’d like to learn more about FreeBSD jails be sure to check out this page

Setting Up the Jail

Base Jail

  1. Open your TrueNAS web console, and click on Jails on the left hand side of the screen.
  2. Click the Add button near the top right.
  3. Enter a name for your jail. In my case I simply selected jenkins
  4. Select a release for your jail. For mine I selected the latest, 12.2.
  5. Click next
  6. In my case I would like the jail to be accessible as a simple hostname like jenkins.local. To do this, simply click DHCP Autoconfigure IPv4. This will create a virtual network device, and cover the needs of most users’ network setup. Click next.
  7. Click through to create the jail.

Setup Mountpoint

These steps will mount a previously created dataset to /srv the (arguably) most appropriate place to store your data, and still have it be accessible by services outside of the jail.

  1. On the Jails page you should now see a jail named jenkins. Click the > (right “arrow”) on the right side of the screen to expand the info.
  2. Click Mount Points.
  3. You’ll likely see no mount points, so click Actions and then Add in the top right.
  4. Use the dropdown to select your dataset source.
  5. In destination, select one of the subpaths. PLEASE NOTE that it would let you select the root, just select something like etc.
  6. Now, replace the text in the Destination field so that it does not read with the end of the directory you selected (like, in the example above .../etc), but ends in srv. If your jail’s name is jenkins your destination should read /mnt/ssd/iocage/jails/jenkins/root/srv
  7. Click submit

Enable Autostart and Start the Jail

  1. Again, return to the Jails mainscreen. (Click Jails on the left menu bar)
  2. Again, use the > arrow on the right side of the jenkins jail line to expand the info.
  3. Click on Edit
  4. Under Basic Properties click to enable Auto-start
  5. Scroll to the bottom and click Save
  6. Once again, on the “main” Jails page, expand the jenkins jail and click Start

Install Jenkins

  1. Once your jail has started, expand the jenkins entry on the Jails page agaain, and click Shell. This should put you as root within your jail.
  2. Install jenkins using the package manager: pkg install -y jenkins
    1. The -y here simply supresses the (arguably) annoying prompts to install
  3. Grab a soda / coffee / beer and wait a minute or few.
  4. Here, you’ll want to have a text editor. I prefer vim but the jail doesn’t have it by default so I’ll also install vim: pkg install -y vim
  5. Enable Jenkins by default, by adding the following line to your /etc/rc.conf file: jenkins_enable=YES
  6. Start Jenkins by running /usr/local/etc/rc.d/jenkins start
  7. Finally, you’ll probably want git installed on the system. Similar to Jenkins or vim, install using the pkg command: pkg install -y git

Connect and Setup Jenkins

Almost done!

  1. Now, assuming your network recognized the jenkins name, you should be able to connect to it using something like http://jenkins.local:8080 or http://jenkins.lan:8080.
    1. If you can’t find it by name, you can find your IP address from the jail’s shell using the ifconfig command.
    2. NOTE: Jenkins on FreeBSD will default to using port 8080, so make sure you include :8080 to your URL.
  2. When you navigate to the page you’ll see that you need the admin password. They tell you where to find it. To access it use the jail’s shell to cat the output of the file. For example, run: cat /usr/local/jenkins/secrets/initialAdminPassword

Finishing Up

Alright, you’re ready to complete your setup! Your desired setup may change a bit, but remember, you likely want to build and/or distribute in the /srv dataset we mounted earlier.