Setting Up Jenkins Nodes on FreeBSD

Jenkins CI is mainly used for continuous testing and deployment of a project. However, you can also use it instead of a task scheduler (crontab): all logs of what happens will be preserved, you can give users access to jobs they can run themselves through the web interface, and, of course, you can run jobs on several servers at once. But to do that, you first need to configure “Jenkins Nodes,” which is what we will do in this article.
I have two favorite server operating systems that I work with all the time: FreeBSD and Debian. Since we have already installed Jenkins on Debian, today I will talk about FreeBSD. The only differences are in the installation of Jenkins itself; the rest of the configuration is the same.
In this article, the fictitious address of the FreeBSD slave node will be 203.0.113.44, and its hostname will be freebsd-server-1.
Installing Jenkins on FreeBSD
I honestly tried installing Jenkins from ports myself:
cd /usr/ports/devel/jenkins/
make install clean
But because of Java, I couldn’t get it to work. Then I handed the job over to portupgrade, and it managed it:
cd /usr/ports/ports-mgmt/portupgrade
make install clean
portupgrade -NR jenkins
On one of the servers (running an old version of FreeBSD), while installing the
/usr/ports/java/openjdk6dependency, I ran into a problem: the installed tar did not understand the “openjdk6-amd64-r316538.tar.xz” archive:tar -tf openjdk6-amd64-r316538.tar.xz tar: Unrecognized archive format tar: Error exit delayed from previous errors.I checked what was being used as “tar,” and it was bsdtar:
readlink /usr/bin/tar bsdtarI decided to try gtar:
cd /usr/ports/archivers/gtar/ make install cleanIt was able to open the file, so I decided to replace bsdtar with gtar:
tar -tf openjdk6-amd64-r316538.tar.xz ... list of some files ... ln -fs /usr/local/bin/gtar /usr/bin/tarAfter that, everything worked successfully!
Generating Keys to Connect to the Slave Node
Log in over ssh to the master node’s server (where the main Jenkins instance is installed) and generate the keys:
sudo su - jenkins
ssh-keygen -t rsa
### Путь до файла ключа /var/lib/jenkins/.ssh/jenkins.freebsd-server-1
Add an ssh configuration by opening “/var/lib/jenkins/.ssh/config” for editing:
Host freebsd-server-1
User jenkins
Hostname 203.0.113.44
Port 22
IdentityFile ~/.ssh/jenkins.freebsd-server-1
Now copy the public key to the freebsd-server-1 server:
ssh-copy-id jenkins@freebsd-server-1
And try connecting:
ssh freebsd-server-1
If you connected successfully, continue; otherwise, check that your settings are correct.
Adding a Node in the Jenkins CI Web Interface
Now log in to the master node’s web interface, then go to "Manage Jenkins" > "Manage Nodes" > "New Node", enter the node’s name, and click OK. After that, fill in the following fields:
# of executors- the number of jobs that can run simultaneously on the slave node. I usually enter “5”;Remote FS root- the path to the Jenkins working directory on the slave node. I usually enter “/var/lib/jenkins/jenkins_fs”;Launch method- select “Launch slave agents on Unix machines via SSH”:Host- enter “203.0.113.44”;Username- enter “jenkins”;Private Key File- the private key we created earlier, “/var/lib/jenkins/.ssh/jenkins.freebsd-server-1”;Port- the SSH server’s TCP port; enter “22”.
Newer versions of Jenkins have Credentials (
"Manage Jenkins" > "Manage Credentials"). If you will have many nodes with similar keys or passwords, it is worth creating a Credential and specifying it when creating a node.
Once configuration is complete, launch the agent Launch slave agent. It will log in to the server over ssh on its own, upload the “slave.jar” file to the directory you specified in “Remote FS root,” and start up.
You can also specify environment variables for your node in the “Environment variables” subsection. Then, when configuring jobs, you can use these variables in the “Execute shell” section.
The NodeLabel Plugin for Parameterizing Jobs
To parameterize jobs, you need to install the NodeLabel Parameter Plugin in Jenkins. Go to "Manage Jenkins" > "Manage Plugins" > "Available" and select “NodeLabel Parameter Plugin.” Click Install without restart. While the plugins are being installed, select “Restart Jenkins when installation is complete and no jobs are running.”
After installing the plugin and restarting Jenkins, you will be able to specify in each job which nodes it should run on. To do this, enable the This build is parameterized checkbox when configuring the job, then click "Add Parameter" > "Node" and select the nodes you need from the list in the Default nodes and Possible nodes sections.
Save the settings. Everything should now work. If not, leave a comment with a detailed description of the problem!
What Else Should You Read?
Comments are closed. Read the original discussion in Russian →