Jenkins and Perlbrew - A "where to" guide

Jenkins works well when your Java code is based on the build philosophy of maven or ant and tucked nicely in one of the popular source code management repositories. (All your code is versioned, right?!?) Building a newly created project will retrieve your code and build it with the system default tools; maven, java or ant.
One of the nice features is the additional "tools" you can install and use to build your projects. Install the 1.6.X version of ant in your node and select it when you create your new project. You'll see in your build output, a preliminary stage where it will install and execute your build.xml with the selected version.
Wouldn't it be nice to have have that similar functionality with Perl?
Jenkins puts these into a common area under the ${JENKINS_HOME}/tools directory. We can install our perl versions in the same location.
At this point, I could discuss the philosophical points of system configuration and the benefits of knowing the preferred brand of beer of each of your admins, but I just need to find a solution that keeps me happy and reserves my admin "chips" for another day. Enter perlbrew.
perlbrew out of the box does a fine job of assuming you need to install itself locally, to you home or ~/ directory. This is ok for your everyday "proof of concept" or a debate on why a module tests just fine on the a development box, but I needed a way to build these puppies in a CI environment.
Let's start with the PERLBREW_HOME environment variable. A quick definition at the start of my script [see previous posts] would place perlbrew anywhere in the directory structure I have permissions and, from a Jenkins project, I would have permissions to the "tools" directory.
So, in the Jenkins "Environment variables" section set the name PERLBREW_HOME to a value of ${JENKINS_HOME}/tools/perl5
(I know I can export this variable in the shell and don't need to use this section, but I'm lazy. Trust me for now.)
Now create a job as a "Build a free-style software project" as "Perlbrew Install" and enter the location of my script that you checked into your SCM (you did commit it, didn't you) or just copy the code into the "Execute shell - Command" section. Maybe some day I'll get this copied to a publicly available site so you won't have so much copying to do...
Now build your job. You'll have perlbrew installed in a few moments.
The convenience of perlbrew comes about by the sourcing of the rc files in your shell. The files define some needed variables perlbrew uses to know where to find itself (how existential) and perl versions you've installed.
Now here's the important part.


  1. Go back to the Jenkins "Environment variables" section and change the variable name to either:


  2. ENV - if you perfer to use sh as your shell
    or
    BASH_ENV if you prefer bash

  3. change the value adding /etc/bashrc to the end


  4. the full value should look like ${JENKINS_HOME}/tools/perl5/etc/bashrc


Jenkins uses sh by default but you can change the default SHELL in the "Shell executable" section to "/bin/bash" or wherever your bash exists.
Now when you create a new job, your "Execute shell" build step will source the file and set not only the PATH but will also set PERLBREW_HOME (see it's not gone for good.)
To test this, create a new job with just "env" as the command.
You might want to add "perlbrew -h" to get you ready for future steps.

Wait! Don't get rid of your "Perlbrew Install" job just yet. If you run it again, after a few days, you might notice that a new version of perlbrew gets installed right over the top of the old one! PERLBREW_HOME always points to the location of perlbrew so you'll be able to schedule it to execute @weekly or @monthly.

Leave a comment

About John Chambers-Malewig

user-pic Perl Hacker