On the above screenshot you can see that we’ve configured the
System Message and number of executors Jenkins will use during builds.

Now let’s secure a bit our Jenkins instance:

As you can see from the above screenshot we’ve configured one user
with full administrator access to the Jenkins instance and we’ve
configured access for the anonymous users.

For more information on securing your Jenkins CI instance, please
refer to the Securing Jenkins
documentation.

And the last thing we are going to configure is the E-mail Notifications,
so that we get notification status about the builds.

As mentioned earlier this is just a basic configuration of our
Jenkins CI instance and you are also advised to play a bit with the
configuration options and check the online documentation as well for
more information about Jenkins.

Setting up a Jenkins job for building a software project

Lets create now a Jenkins project that will build and test a real-world
project. For the purposes of this example we will be building and
testing the FreeBSD’s pkgng project.

First lets start with installing a few plugins for Jenkins.

We will need the following plugins installed before being able to
build our example project.

In order to install the needed plugins navigate through your Jenkins CI
instance to Manage Jenkins -> Manage Plugins -> Available and
select the above plugins, then click on the Install button.

Once the above plugins have been installed we need to configure the
Git plugin, so navigate to Manage Jenkins -> Configure System and
scroll down to the Git section

If you see the There's no such executable git in PATH: /sbin, /bin, /usr/sbin, /usr/bin.
like on the screenshot below you will need to update your path to the Git executable:

As with FreeBSD any software installed that is not part of the base
system gets installed in /usr/local, so you need to update the path
to the Git executable to /usr/local/bin/git.

Now that we have the plugins installed and configured, lets create our
first Jenkins job. To do that navigate to New Job, give the job a name
and select the Build a free-style software project, then press the
OK button.

Setting up an upstream project in Jenkins

A few things to note here is that our Jenkins job will be
configured in the following way:

One upstream project that will poll the remote Git repository every 30 minutes

If there are new changes made in the remote Git repository we pull those changes

Archive the Git repository so that downstream projects can clone it and then build it

Trigger a build on the downstream projects

Downstream projects will be building the project using GCC and LLVM Clang

In other words our upstream project is the one that triggers a
build on the downstream projects whenever a new change to Git
repository is made.

Once you create a new job in Jenkins you need to configure it.

On the above screenshot we have configured the following things:

Description of the job

We want to keep max of 100 builds for the project

The project link at Github

The next thing we need to configure is Source Code Management.
This is where we define the remote Git repository,
the branches we want to build and the repository browser.

Now, lets continue to the Build Triggers. The Build Triggers tell
Jenkins when and how a build is being scheduled.

In the screenshot above we tell Jenkins to poll the remote Git
repository every 30 minutes for new changes.

One last thing that we are going to do is to prepare the repository
for cloning on the downstream projects as well.

This saves the time needed for doing a clone of the Git repository
and also makes sure that all builds we make are done from a clean state,
meaning a full rebuild of project itself.

To do that we need to select Archive for Clone Workspace SCM in the
Post-build Actions section as shown in the screenshot below:

And that was it with the configuration of our upstream project in
Jenkins. Now we can configure our downstream projects which will
take care of building pkgng with GCC and LLVM Clang.

Setting up downstream projects in Jenkins for FreeBSD’s pkgng

Just like in the previous step where we’ve configured the
upstream pkgng project in Jenkins we will now configure a
downstream project for pkgng* for building the project
using GCC and LLVM Clang.

Navigate to New Job -> Build a free-style software project and
use a project name pkgng-gcc.

Now we will add the downstream project description,
max number of builds and Github project just like we did in the
previous step.

Next we do the configuration in the Source Code Management section.
Here we are going to use the workspace of the upstream pkgng
project which we’ve already archived and now we can use for building.

In Source Code Management select Clone Workspace and choose
pkgng as the Parent Project as shown in the screenshot below:

In the Build Triggers section we will configure that our project
gets build after the upstream pkgng project is built.

This creates the relation between the upstream and downstream
projects in Jenkins.

Now it is time to define the commands used to perform the actual build
of the project and that is defined in the Build section.

To do that in the Build section we select Execute shell
option define the commands used to build the project as shown in the
screenshot below.

To build the project we just add one line:

env CC=gcc make

Now whenever a new change being pushed to the remote Git
repository of pkgng this will trigger a new build of the project
using GCC on the downstream project.

In order to create another downstream project using LLVM Clang you can
follow the steps of this section, and the only change you
need to do is to replace the command for building the project with the
one below:

env CC=clang make

In order to test that everything works as expected just go ahead and
trigger a build on the upstream pkgng project and monitor the
result in it’s downstream projects for GCC and LLVM Clang.

Further reading

As mentioned in the beginning in this post this is just a quick and
dirty introduction to Continuous Integration with Jenkins under FreeBSD.

You are also advised to check the online documentation about Jenkins
and Continuous Integration on the topic.

Jenkins also provides lots of ready-to-use plugins which extend
further it’s functionality. You can check the
available plugins for Jenkins here
and install them as needed.