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
- Open your TrueNAS web console, and click on
Jails
on the left hand side of the screen. - Click the
Add
button near the top right. - Enter a name for your jail. In my case I simply selected
jenkins
- Select a release for your jail. For mine I selected the latest, 12.2.
- Click next
- In my case I would like the jail to be accessible as a simple hostname like
jenkins.local
. To do this, simply clickDHCP Autoconfigure IPv4
. This will create a virtual network device, and cover the needs of most users’ network setup. Click next. - 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.
- On the
Jails
page you should now see a jail namedjenkins
. Click the>
(right “arrow”) on the right side of the screen to expand the info. - Click
Mount Points
. - You’ll likely see no mount points, so click
Actions
and thenAdd
in the top right. - Use the dropdown to select your dataset source.
- In destination, select one of the subpaths. PLEASE NOTE that it would let you select the root, just select something like
etc
. - 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 insrv
. If your jail’s name isjenkins
your destination should read/mnt/ssd/iocage/jails/jenkins/root/srv
- Click submit
Enable Autostart and Start the Jail
- Again, return to the
Jails
mainscreen. (ClickJails
on the left menu bar) - Again, use the
>
arrow on the right side of thejenkins
jail line to expand the info. - Click on
Edit
- Under
Basic Properties
click to enableAuto-start
- Scroll to the bottom and click
Save
- Once again, on the “main”
Jails
page, expand thejenkins
jail and clickStart
Install Jenkins
- Once your jail has started, expand the
jenkins
entry on theJails
page agaain, and clickShell
. This should put you as root within your jail. - Install jenkins using the package manager:
pkg install -y jenkins
- The
-y
here simply supresses the (arguably) annoying prompts to install
- The
- Grab a soda / coffee / beer and wait a minute or few.
- 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
- Enable Jenkins by default, by adding the following line to your
/etc/rc.conf
file:jenkins_enable=YES
- Start Jenkins by running
/usr/local/etc/rc.d/jenkins start
- 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!
- Now, assuming your network recognized the
jenkins
name, you should be able to connect to it using something likehttp://jenkins.local:8080
orhttp://jenkins.lan:8080
.- If you can’t find it by name, you can find your IP address from the jail’s shell using the
ifconfig
command. - NOTE: Jenkins on FreeBSD will default to using port 8080, so make sure you include
:8080
to your URL.
- If you can’t find it by name, you can find your IP address from the jail’s shell using the
- 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.