Ensure java is installed, then add jenkins apt-key and install:
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
What this does (From Jenkins Website):
/etc/init.d/jenkins
for more details./etc/default/jenkins
will capture configuration parameters for the launch like e.g JENKINS_HOME8080
. top
' UNIX command should show that a user named jenkins is now consuming some %MEM. More information on the process can be found via:
ps -aux | grep jenkins
localhost:8080
" in a browserHowever...
sudo service <stop/start/restart>
update-rc.d jenkins disable
Set up security - Important as default settings allows any user on the network or VPN to run any bash command or executable through jenkins given the IP and port number.
Enable Security
: YesTCP port for JNLP slave agents
: RandomAccess Control
: Unix user/group database- Use 'Test' under Unix user/group database access control to troubleshoot: I had to add jenkins to the group 'shadow' with
sudo usermod -aG shadow jenkins
Authorization
: Matrix Authorization Strategy - need to add user here as it doesn't add UNIX users to the table automatically (managed to lock myself out by not doing this). Note the tick all box on the rightMarkup Formatter
: Plain TextPrevent Cross Site Request Forgery exploits
: yes, default crumb issuerEnable Slave -> Master access control
: yes
Set up plugins (Github, Bitbucket...)
Manage Jenkins
> Manage Plugins
> Available
> search for 'git plugin' > download and install on restartPipeline
plugin is handy for advanced useage, but not requiredSet Environment variables
.bashrc
Manage Jenkins
> Configure System
Environment variables
box under "Global Properties" and add your anaconda path to PATH:Name
: PATH, Value
: /path/to/anaconda/bin:$PATHNew Job > Freestyle project
Discard old builds
and choose a number of builds to keep/how long to keep themAdditional Behaviours
> Add
> Check out to a sub-directory
: Leaving this blank is fine as the code wil be checked out into the project workspace.Build Trigger
> 'Poll SCM
' and 'Build when a change is pushed to GitHub
' to only build the project if the git repository has changed. You'll still need to set a schedule for how often it will check - see the question mark by schedule for help. H/5 * * * *
post-commit
hooks can also be set up for this, but difficult if Jenkins is behind a firewall that GitHub cannot successfully send packets through.
Execute shell
: ./Jenkins_build.sh
Pytest
error reports can be published on the build status page by added Post-build Actions
> publish JUnit test result report
> Test report XLMs: filename.xml
and adding the junitxml
flag to py.test in Jenkins_build.sh:
py.test --junitxml=filename.xml
Build Now
A Virtual Machine may be useful for Jenkins servers running on shared clusters where admin priveleges are not given.
I'm going to describe the process for setting up an Ubuntu
vagrant init Ubuntu/xenial64
Now need to edit the vagrant file to allow port forwarding, i.e. uncomment/edit the line
config.vm.network "forwarded_port", guest: 8080, host: [Host Port number]
Host Port number
here should be a memorable number that is not in use
netstat -a
may help to show which ports are in useEnable shell script provisioning in Vagrantfile, i.e. add the following line before end
config.vm.provision "shell", path: "setup.sh", privileged: true
Add a setup.sh
bash file so that we have a software test-bed (I suppose this will require a python environment - Conda?, C compilers, C++ compiler, Fortran, cmake) plus the Jenkins dependencies (Java) and installation. Another provisioner would be better in general, however if you plan to run tests on a Debian machine, this is ok. My bash file contents in setup.sh
are:
------------------------------------------------------------------------------------------------
# Guest machine setup script for a Jenkins server and software test-bed
# @author Paul Chambers
# @date 11/01/2016
apt-get update
# Misc tools
apt-get -y install cmake, git, hg
# Install compilers
apt-get -y install build-essential, gfortran
# Install Anaconda python distribution to /home/vagrant/anaconda2
wget https://3230d63b5fc54e62148e-c95ac804525aac4b6dba79b00b39d1d3.ssl.cf1.rackcdn.com/Anaconda2-2.4.1-Linux-x86_64.sh
chmod +x Anaconda2-2.4.1-Linux-x86_64.sh
VGR_HOME=/home/vagrant
CONDA_PATH=$VGR_HOME'/anaconda2'
BASHRC=$VGR_HOME'/.bashrc'
./Anaconda2-2.4.1-Linux-x86_64.sh -b -p $CONDA_PATH
echo '# Added during vagrant setup to correct Anaconda python path:' >> $BASHRC
echo 'export PATH='$CONDA_PATH'/bin:$PATH' >> $BASHRC
echo '' >> $BASHRC
source $BASHRC
conda update conda
conda update anaconda
# Install java (required for jenkins)
apt-get -y install default-jdk
# Jenkins specific setup:
wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
apt-get update
apt-get -y install jenkins
------------------------------------------------------------------------------------------------
make it executable...
chmod +x setup.sh
Note: Other settings such as RAM, CPU number and virtual hard drive size can and probably should also be set in the vagrant file.
Start the vagrant machine :
vagrant up
To control the machine later, ssh into the vagrant machine with
vagrant ssh
And use the normal vagrant commands to control the virtual machine once created i.e.
vagrant suspend/halt
# suspend/shut down (vagrant up to recover)
vagrant destroy
# delete the machine
It seems security can be switched off directly in the $JENKINS_HOME/config.xml although this requires sudo access so not a huge risk
this might be useful for moving existing jenkins jobs from one computer to another
Master-slave builds could be useful to avoid crashing the master Jenkins node
Sizing the hard disk and RAM for vagrant machines should be important factors to consider for shared Jenkins servers