Groovy script on slave node

2,974 views
Skip to first unread message

Scott Ellis

unread,
Mar 26, 2013, 11:20:24 PM3/26/13
to jenkins...@googlegroups.com
I've been working on this for two days and have googled this to death.  There are just too many unknowns for me and I need some help.

The original problem I'm having is that I want to deploy two war files from a multi-module maven project, and Jenkins is only giving me the option to deploy one--I'm deploying to two different tomcat containers.  So I decided to trigger two different deployment jobs to get it done instead.  The problem became: what is the actual name of the war file, including the version?

This isn't easily available.  I found a post on how to acquire the name from the generated pom, which wasn't perfectly in line with my set up, but useful.  The concept requires that I call a post-build groovy script, that must be run as a system script so that I can acquire variables in context of the build environment.  So I do this, but the script requires that I add to the classpath some third-party jars.  

So long story short, the script will run fine as I'm testing it locally, but my build declares a slave node upon which this script must run.  Only the master node has this groovy environment set up correctly, and I need Jenkins to transfer my deployment to the slave.  I found this thread, with this reply that I found interesting:

Our shop gets around this by using the "Run SSH command on slave" option to start our slaves, and specifying a shell script that rsyncs a tools directory from the master to the slave before starting the slave process.  The master tools directory contains the JDK plus all the tools we need such as Ant, Maven, Groovy and so on.  This has the added advantage that we can push tool updates out to all the slaves by just updating the master directory and restarting the slaves.

This I think would solve my issue, but I am a rookie Linux user and do not know much about his subject.  Some, but not enough.  I would love it if someone could explain to me how to get my groovy installation to the slave node.  I know there is an option to install automatically, which I've attempted, but I don't see anything.  Where does it go if it works?  My build slave node home appears to be at /Users/Shared/Jenkins/Home/jenkins-slaves/build-slave (build-slave being the name I've assigned it).  I'm good right now with simply copying my groovy installation onto the slave node, but where should it go?  

I tried tarring the installation, complete with my modifications to groovy-starter.conf, which adds the third-party libraries needed by the new script.  In the groovy configuration I've configured groovy to install automatically, and I chose the extract *.tar.gz option and specified with a file-style url the tar file.  It's lame, but that's what I've tried.

Groovy runs during the build, but I'm getting class not found errors because my third party jars are not being found.

I hope someone can point me in the right direction.

Thanks,

Scott 

Les Mikesell

unread,
Mar 26, 2013, 11:49:32 PM3/26/13
to jenkins...@googlegroups.com
On Tue, Mar 26, 2013 at 10:20 PM, Scott Ellis <jacke...@yahoo.com> wrote:
>
>> Our shop gets around this by using the "Run SSH command on slave" option
>> to start our slaves, and specifying a shell script that rsyncs a tools
>> directory from the master to the slave before starting the slave process.
>> The master tools directory contains the JDK plus all the tools we need such
>> as Ant, Maven, Groovy and so on. This has the added advantage that we can
>> push tool updates out to all the slaves by just updating the master
>> directory and restarting the slaves.
>
>
> This I think would solve my issue, but I am a rookie Linux user and do not
> know much about his subject. Some, but not enough. I would love it if
> someone could explain to me how to get my groovy installation to the slave
> node. I know there is an option to install automatically, which I've
> attempted, but I don't see anything. Where does it go if it works? My
> build slave node home appears to be at
> /Users/Shared/Jenkins/Home/jenkins-slaves/build-slave (build-slave being the
> name I've assigned it). I'm good right now with simply copying my groovy
> installation onto the slave node, but where should it go?

I think the slave downloads directly from the internet if you use the
auto-install option and it goes in the slave's home directory. I
haven't used this specifically for groovy libraries, but for other
components we have a directory shared from the jenkins server (but it
could be any common server) via both nfs and samba, and windows node
access it via UNC paths (\\server\path) and all linux nodes mount it
in the same location.

--
Les Mikesell
lesmi...@gmail.com

Scott Ellis

unread,
Mar 28, 2013, 2:56:07 PM3/28/13
to jenkins...@googlegroups.com
Les,

I appreciate the reply.  I've been struggling with this still and would like to understand your setup better.  It seems to me that you must have entries in your windows classpath that refers to mounted folders.  So in my case, if I wanted to use groovy from a common location using your technique, you would modify the classpath of the slave node to refer to a groovy installation on the mounted drive.  

Do you modify the classpath then of the slave node in node settings?

Here is my specific problem, and an easy test to see if the problem is occurring:

  1. I have a local installation of groovy.  I go to Jenkins->Manage Jenkins->Configure System
  2. In the Groovy section of the page, I click "Groovy installations..."
  3. I click Add Groovy, uncheck "Install Automatically", give this installation the name "Groovy 2.1.2", and specify my home folder
    1. Maybe this is where I could take advantage of your technique?!  I'm on a Mac and the entire build is happening on this system.   I have a single slave node and a master.  How do I create a global reference to a location in linux that will work from the master or slave node?

Les Mikesell

unread,
Mar 28, 2013, 3:11:38 PM3/28/13
to jenkins...@googlegroups.com
On Thu, Mar 28, 2013 at 1:56 PM, Scott Ellis <jacke...@yahoo.com> wrote:
> Les,
>
> I appreciate the reply. I've been struggling with this still and would like
> to understand your setup better. It seems to me that you must have entries
> in your windows classpath that refers to mounted folders. So in my case, if
> I wanted to use groovy from a common location using your technique, you
> would modify the classpath of the slave node to refer to a groovy
> installation on the mounted drive.
>
> Do you modify the classpath then of the slave node in node settings?

No, as I said, I don't do it specifically with groovy myself and I'm
not sure if anyone even uses it with java jars. For things like boost
or running ant versions we use the jenkins envirornment/tool setup to
supply a \\host\path location on windows or a path to a configured nfs
mount location on linux. Windows has the complication that mapped
drive letters are specific to login sessions so you can't just map a
drive manually and expect jenkins to see the same location.

> Here is my specific problem, and an easy test to see if the problem is
> occurring:
>
> I have a local installation of groovy. I go to Jenkins->Manage
> Jenkins->Configure System
> In the Groovy section of the page, I click "Groovy installations..."
> I click Add Groovy, uncheck "Install Automatically", give this installation
> the name "Groovy 2.1.2", and specify my home folder
>
> Maybe this is where I could take advantage of your technique?! I'm on a Mac
> and the entire build is happening on this system. I have a single slave
> node and a master. How do I create a global reference to a location in
> linux that will work from the master or slave node?

I don't run any builds on the master, so I don't have to be concerned
about the location there. First you need to decide what to use as the
server for the shared directory. It doesn't have to be either of
the master or slave machines, and if it isn't you can simply nfs-mount
it into the same place on all targets so the same classpath will work.
If you do use the master as the file server you might need a symlink
to the real location to make the path look the same. I'd recommend a
read-only nfs export so you don't have to worry too much about
security issues - and then you just repeat the mount configuration on
any additional slaves you might add.

--
Les Mikesell
lesmi...@gmail.com

Geoff Cummings

unread,
Mar 28, 2013, 5:03:57 PM3/28/13
to jenkins...@googlegroups.com
Hi,

Typing this out on my phone so apologies if it doesn't make sense :)

Not sure how to help with the groovy setup, but was trying to understand why you need the complex groovy script.

From what I understand your main build produces 2 war files, I assume they have a maven version in the name and perhaps a build number so the name of the wars may change.

I have not used the deploy plugin but from what I have read it will let you specify multiple files to deploy by using *.war but only to one tomcat server?

Do you need both files deployed to both tomcat servers, or one file to one server and the other file to the second server?

My initial thoughts are:

1. main build job would archive both the Wars as artifacts

2. Deploy to server 1 job: use the Copy artifacts plugin to copy the artifacts from main build job to the workspace of deploy job 1. This doesn't need the name of the files. it can copy all or use wildcards to filter files.  Then use the deploy plugin to deploy wars to server 1.

3. Deploy to server 2 job would be similar but deploy to server 2...


Geoff
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages