How to chroot jenkins build?

I want to automate builds in chroot:

sudo chroot mychroot
apt-get install git build-essential make -y
git clone myrepo
cd myrepo/src
make

      

From this thread it seems that my configuration in Manage Jenkins -> Configure System should be:

Name: trusty
Tool: pbuilder
Advanced configuration: checked
Additional arguments: --distribution trusty --debootstrapopts --variant=buildd

Shell command:
Repositories:
Name: universe
Repository URL: deb http://us.archive.ubuntu.com/ubuntu/ trusty universe
Keyfile URL: http://archive.ubuntu.com/ubuntu/project/ubuntu-archive-keyring.gpg

      

I also added jenkins to the file /etc/sudoers

as discussed in this issue .

Can anyone share their config? The wiki is fine, but I'm a little missing:

What's described here is exactly what I want:

Creates a new debootstrap-based chroot.
Installs build-essential, mercurial, etc.
Fetches the shource.
Runs make.
Copies the files produced in ./binary-out/ to a safe location.
Cleans up.

      

+3


source to share


1 answer


If it is desirable to prepare the chroot ahead of time (say all jobs use the same configuration) then what you want can be easily achieved on the SSH slave using the following configuration in / etc / ssh / sshd_config on the slave

Match User jenkins
      ChrootDirectory /var/chroot/
      X11Forwarding no
      AllowTcpForwarding no

      



When Jenkins logs into the SSH slave to do a build, it will be automatically loaded into the chroot without having to add Jenkins to sudoers, create a chroot, and install dependencies before the build magic can happen.

In cases where Jenkins will always be in the same chroot on a machine, this is much easier, not to mention a less error prone route.

+2


source







All Articles