How to Configure a Jenkins project to run ant from a Windows Slave

1,983 views
Skip to first unread message

John Park

unread,
May 1, 2014, 9:42:42 PM5/1/14
to jenkins...@googlegroups.com
Hi All,

Glad this forum is around, I could sure use some help.  Here's my story:

I have an ant script that's on the windows slave machine that I would like to run from the Jenkins browser, which is located on another server (master).  I followed the steps to set up a Master-Slave connection using the Java Web Start method, and that seemed to work, and saw that the Jenkins service was up and running.  I verified an established jenkins-service connection between the master and slave machines.  I have verified that the owner of the jenkins service belongs to the user that will kick off the ant script.  I have also verified from the browser that my slave windows node successfully is connected with Jenkins.  All looks well up to this point.

I then created a new job on the browser with intentions of executing the ant script that resides on the slave.  I made sure to check the 'Restrict where this project can be run' box and added my slave node label. At this point, I thought that Jenkins would delegate this job to the slave everytime this job was executed.  I then proceeded to create a build step that would execute ant.bat from the slave, and saved the project.  The job kept failing, telling me that it could not find the path specified. I then realized that the job was probably searching for the directory in the master, and not the slave.  I looked around some more, but couldn't figure out how to configure the job properly in order for Jenkins to communicate/connect with the slave.

Anything I might be missing here?

Any help or advice is greatly appreciated.

Thanks,

JP


Mark Waite

unread,
May 1, 2014, 10:00:13 PM5/1/14
to jenkins...@googlegroups.com
The machine which is trying to execute your ant.bat file probably does not have the Ant bin directory in its path.  Since it can't find the ant.bat file, it fails.  There are a few approaches you might consider:

- Modify the PATH on the Windows slave to include the Ant bin directory (the location of ant.bat)
- Configure Jenkins to automatically install ant for you (global configuration), then select that specific ant version in your job
- Start the Windows slave from a batch file that modifies the PATH to include the Ant bin directory

Mark Waite


--
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/d/optout.



--
Thanks!
Mark Waite

Les Mikesell

unread,
May 1, 2014, 11:57:25 PM5/1/14
to jenkinsci-users
On Thu, May 1, 2014 at 9:00 PM, Mark Waite <mark.ea...@gmail.com> wrote:
> The machine which is trying to execute your ant.bat file probably does not
> have the Ant bin directory in its path. Since it can't find the ant.bat
> file, it fails. There are a few approaches you might consider:
>
> - Modify the PATH on the Windows slave to include the Ant bin directory (the
> location of ant.bat)
> - Configure Jenkins to automatically install ant for you (global
> configuration), then select that specific ant version in your job
> - Start the Windows slave from a batch file that modifies the PATH to
> include the Ant bin directory
>

It might be a little easier to follow things if you add at least 2 jdk
and ant versions in your global config and set their locations in the
node configurations (even if you don't currently need more than one of
each...). Then the job configuration will give you a version
selection for the tool versions and if anything isn't found you'll
have a better idea of where the location is controlled.

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

John Park

unread,
May 2, 2014, 1:27:32 AM5/2/14
to jenkins...@googlegroups.com
Les, Mark,

Thank you so much for you responses. I did verify that ANT_HOME is set and in my PATH within my environment:
variables on the slave machine (I did an echo for %PATH%, and saw my the path to my ANT bin folder).  I think the problem is that I am not configuring the job correctly from the jenkins browser.  Here is what I did:

After verifying that a Java Web Start connection was successful, I created a new job, checked the 'Restrict where this project can be run' box.

I then added a new build step to execute a windows batch file.  I then added the command:

C:\Program Files\<apache-ant>\bin\ant.bat <path to build.xml> all

This wouldn't work, so what I did next was throw some commands in another .bat.  Here's what I had in the script:

cd <path to build.xml>
ant all

No dice, kept getting the following error:

"C>:\<path to my .bat file>
The system cannot find the path specified.

Would I need to have a set command in my bat file to point to my ANT_HOME bin directory?

Thanks,

-John P.



--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/0ELSkd80t_Q/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

Richard Bywater

unread,
May 2, 2014, 2:48:56 AM5/2/14
to jenkins...@googlegroups.com
Is thre a reason you aren't using an Ant Build Step and instead are doing it via a Batch script step?

Richard.
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.

John Park

unread,
May 2, 2014, 10:25:40 AM5/2/14
to jenkins...@googlegroups.com
To be honest, I have never tried invoking ant from the build step in jenkins..I just took a look at it, but I don't see how this would be more beneficial (or easier) for me, since I have everything already set up on the slave machine...all I should be doing is executing an ant command to run the script. 

Is there some benefit to invoking ant in jenkins vs executing it from the slave?

Thanks for your response.

-John P.

Les Mikesell

unread,
May 2, 2014, 10:53:36 AM5/2/14
to jenkinsci-users
On Fri, May 2, 2014 at 9:25 AM, John Park
<john...@sightlinesystems.com> wrote:
> To be honest, I have never tried invoking ant from the build step in
> jenkins..I just took a look at it, but I don't see how this would be more
> beneficial (or easier) for me, since I have everything already set up on the
> slave machine...all I should be doing is executing an ant command to run the
> script.
>
> Is there some benefit to invoking ant in jenkins vs executing it from the
> slave?

I don't think you understand. Invoking ant in jenkins will execute it
on the slave where the job runs. But it also lets you set the version
and location for ant (and the jdk to use) in a high-level way. That
is, you can give the versions a name in the global jenkins config, and
set (potentially different) locations for the tools in each node
config. And you can pick the versions in your job file (if there are 2
or more). Then, even if ant and the jdk(s) are installed in
different locations on your own workstation, you can tell jenkins to
run the same ant job from the SCM and it will work regardless of which
node runs it.

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

John Park

unread,
May 2, 2014, 11:56:28 AM5/2/14
to jenkins...@googlegroups.com
Hi Les, 

OK, I think I get what you're saying, so this is what I did:

I set ant and java globally in jenkins and pointed java home and ant home to directories on the jenkins machine (master)

I then added those global settings to my slave node.

I then added a build step to invoke ant, added the global ant setting, added which target i wanted to run, included the path to the build.xml on the slave machine. 

I ran the job, but it still failed incidcating that it could not find the specified path to the build.xml..

I'm convinced that Jenkins (master) is not properly delegating my job to the slave machine...to test this, I had ant execute a simple test batch file i created to echo "hello world" from the slave, but I got a message saying that it didn't recognize tha batch file...I then tested this locally from a command prompt on the jenkins server, where the .bat doesn't exist, and got the same message.

Again, thanks for the input and advice, but I think the root of my problem here is  getting the master to properly delagate control to the slave machine. 

Thanks, 

-John P.




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

Les Mikesell

unread,
May 2, 2014, 12:09:53 PM5/2/14
to jenkinsci-users
On Fri, May 2, 2014 at 10:56 AM, John Park
<john...@sightlinesystems.com> wrote:
> Hi Les,
>
> OK, I think I get what you're saying, so this is what I did:
>
> I set ant and java globally in jenkins and pointed java home and ant home to
> directories on the jenkins machine (master)
>
> I then added those global settings to my slave node.

On the slave node config, the path should be to the location on that
slave. At least if it is different from the global entry.

> I then added a build step to invoke ant, added the global ant setting, added
> which target i wanted to run, included the path to the build.xml on the
> slave machine.
>
> I ran the job, but it still failed incidcating that it could not find the
> specified path to the build.xml..

It expects build.xml to be in the root of the (usually checked-out
from SCM) workspace. Or you can give an explict path if it is
elsewhere for some reason.

> I'm convinced that Jenkins (master) is not properly delegating my job to the
> slave machine...to test this, I had ant execute a simple test batch file i
> created to echo "hello world" from the slave, but I got a message saying
> that it didn't recognize tha batch file...I then tested this locally from a
> command prompt on the jenkins server, where the .bat doesn't exist, and got
> the same message.

You should see which node ran a job over at the top left of the build # page.

> Again, thanks for the input and advice, but I think the root of my problem
> here is getting the master to properly delagate control to the slave
> machine.

That is controlled by the 'restrict where job can run' item in the job
config. You can use nodenames or labels there. It is a good idea to
always give the nodes labels according to their capabilities and
restrict jobs to labels since that makes it easy to add more nodes for
certain build types as the load increases or to fail over as slaves
are down/replaced.

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

John Park

unread,
May 2, 2014, 12:56:23 PM5/2/14
to jenkins...@googlegroups.com
Silly question, does the build.xml that's on the slave have to be on the master machine's root workspace directory in order for it to run on the slave? 

I made changes to the node configuration based on your pointers, and re-ran the project.  On this try, I gave an explicit path to the build file, then got this message:

Started by upstream project "master_slave_test" build number 51
originally caused by:
 Started by user John Park
[EnvInject] - Loading node environment variables.
Building on master in workspace <http://build:80/job/master_slave_test/default/ws/>
FATAL: Unable to find build script at <http://build:80/job/master_slave_test/default/ws/build.xml/"C>:\Builds\build.xml"
Build step 'Invoke Ant' marked build as failure

Seems like there's a syntax error based  on the above message, as it looks to close the C: drive within the URL tag.  

I then moved the build file to the jennkins/ directory on the slave machine and re-ran, but got the same message:

Started by upstream project "master_slave_test" build number 53
originally caused by:
 Started by user John Park
[EnvInject] - Loading node environment variables.
Building on master in workspace <http://build:80/job/master_slave_test/default/ws/>
FATAL: Unable to find build script at <http://build:80/job/master_slave_test/default/ws/build.xml>
Build step 'Invoke Ant' marked build as failure

Some other potential useful info: 

The path I gave to ant home and java home when configuring globally was only to the apache ant and jdk folders, i did not include bin in the path
Same goes for configuring the path in the nodes config.

Based on the error message, the job seems to be executing from the master, and not the slave. 

Thanks, 

-John P.



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

Les Mikesell

unread,
May 2, 2014, 3:05:52 PM5/2/14
to jenkinsci-users
On Fri, May 2, 2014 at 11:56 AM, John Park
<john...@sightlinesystems.com> wrote:
> Silly question, does the build.xml that's on the slave have to be on the
> master machine's root workspace directory in order for it to run on the
> slave?

No, the slave has its own workspace and doesn't have anything to do
with the filesystem the master sees. It can be confusing because the
master web interface shows a 'workspace' folder icon with files - but
that is actually a view from the node that did the last build.

> I made changes to the node configuration based on your pointers, and re-ran
> the project. On this try, I gave an explicit path to the build file, then
> got this message:
>
> Started by upstream project "master_slave_test" build number 51
> originally caused by:
> Started by user John Park
> [EnvInject] - Loading node environment variables.
> Building on master in workspace

That wouldn't happen if your job has a 'restrict where this job can
run' set to a slave node.

> <http://build:80/job/master_slave_test/default/ws/>
> FATAL: Unable to find build script at
> <http://build:80/job/master_slave_test/default/ws/build.xml/"C>:\Builds\build.xml"
> Build step 'Invoke Ant' marked build as failure
>
> Seems like there's a syntax error based on the above message, as it looks
> to close the C: drive within the URL tag.

If your build.xml is in the job's top-level directory you don't need
to specify a path.

> I then moved the build file to the jennkins/ directory on the slave machine
> and re-ran, but got the same message:
>
> Started by upstream project "master_slave_test" build number 53
> originally caused by:
> Started by user John Park
> [EnvInject] - Loading node environment variables.
> Building on master in workspace
> <http://build:80/job/master_slave_test/default/ws/>
> FATAL: Unable to find build script at
> <http://build:80/job/master_slave_test/default/ws/build.xml>
> Build step 'Invoke Ant' marked build as failure

Are you not using a source control repository (subversion, git, etc.)?
That is the typical and probably best way to handle things since it
takes care of the transport of the code/build scripts etc. to whatever
node/workspace needs it. Otherwise you'll need some other way to
update the files in the workspace of the slave that is going to do the
build.

> Some other potential useful info:
>
> The path I gave to ant home and java home when configuring globally was only
> to the apache ant and jdk folders, i did not include bin in the path

Yes, I think it figures out where to execute ant from the ANT_HOME
setting, and that in turn will find java by looking through an
assortment of environment settings.

> Same goes for configuring the path in the nodes config.
>
> Based on the error message, the job seems to be executing from the master,
> and not the slave.

Yes, fix the 'restrict where to build' first. And if your build.xml
is at the top of the workspace, just remove your explicit reference to

John Park

unread,
May 2, 2014, 3:41:31 PM5/2/14
to jenkins...@googlegroups.com
Hi Les, 

Ok, I think the slave node is properly being called to run the job as I see the message from the jenkins console output that it's delegating to the slave node using the label which I assigned.  

To answer your question about subversion, we are not using svn for this job.  This job is simply to deploy our build to the slave windows environment using the provided ant script.There is a target in the ant script to copy the build files from our build machine and copy them over to the slave machine.  So basically, all we want jenkins to do is execute our ant script which deploys our software. There's probably an easier way to do this in Jenkins, but since i've gone this far, i'd rather make it work via master/slave method now, haha. 

You mention that if the build.xml is in the top level directory, an explicit path isn't needed in the job.   By top level directory, do you mean C:/jenkins? or C:/jenkins/workspace/my_jenkins_job/  ?

Thanks for hanging with me Les, I definitely owe you a beer...or 5. 

jp



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

Les Mikesell

unread,
May 2, 2014, 3:59:53 PM5/2/14
to jenkinsci-users
On Fri, May 2, 2014 at 2:41 PM, John Park
<john...@sightlinesystems.com> wrote:
>
> Ok, I think the slave node is properly being called to run the job as I see
> the message from the jenkins console output that it's delegating to the
> slave node using the label which I assigned.
>
> To answer your question about subversion, we are not using svn for this job.
> This job is simply to deploy our build to the slave windows environment
> using the provided ant script.There is a target in the ant script to copy
> the build files from our build machine and copy them over to the slave
> machine. So basically, all we want jenkins to do is execute our ant script
> which deploys our software. There's probably an easier way to do this in
> Jenkins, but since i've gone this far, i'd rather make it work via
> master/slave method now, haha.

Jenkins does have some of its own deployment concepts and plugins, but
it is good to get your own script working first. I'd still consider
sticking the build.xml in svn somewhere just to make sure it is always
up to date and appears in the right place since jenkins will take care
of that grunge work for you.

> You mention that if the build.xml is in the top level directory, an explicit
> path isn't needed in the job. By top level directory, do you mean
> C:/jenkins? or C:/jenkins/workspace/my_jenkins_job/ ?

C:/jenkins/workspace/my_jenkins_job/
You could have a lot of jobs, each with different build.xml files.
Also note that the C:/jenkins/ part is something you could change in
the node config.

> Thanks for hanging with me Les, I definitely owe you a beer...or 5.

No problem.

--
Les Mikesell
lesmi...@gmail.com
Reply all
Reply to author
Forward
0 new messages