可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Jenkins master is running on Windows. I have connected a MAC as jenkins slave using java webstart. I have installed ANT in the slave (MAC) and updated PATH accordingly. I am able to run ant programs locally in the slave machine.
When i run the job from jenkins, It is not invoking ant and fails with below error.
Please clarify.
Building remotely on QAXXX in workspace /Users/uselvvi/jenkins/workspace/QG_LOCALIZATION_STAGING
Cleaning up /Users/uselvvi/jenkins/workspace/QG_LOCALIZATION_STAGING/.
Updating https://<SVNRepo>/SVN at revision '2014-03-24T15:55:41.180 -0500'
At revision 1196
no change for https://<SVNRepo>/SVN since the previous build
[QG_LOCALIZATION_STAGING] $ ant -DLOCALE=en_US -DBROWSER=IE -DENVIRONMENT=QA1 -DSUITE=STAGING RunTestNGSuite
FATAL: command execution failed.Maybe you need to configure the job to choose one of your Ant installations?
java.io.IOException: Cannot run program "ant" (in directory "/Users/uselvvi/jenkins/workspace/QG_LOCALIZATION_STAGING"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:773)
at hudson.Launcher$ProcStarter.start(Launcher.java:353)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:998)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:965)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:328)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at hudson.remoting.Engine$1$1.run(Engine.java:63)
at java.lang.Thread.run(Thread.java:744)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:185)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
... 15 more
Build step 'Invoke Ant' marked build as failure
Archiving artifacts
Finished: FAILURE
EDIT: I am using 'Invoke ANT'. Same setup is working fine in windows slave.
回答1:
OK This is what I had to do..
Even after ensuring that PATH, ANT_HOME is set correctly, i could not make my default ANT work with Jenkins. I wanted to use 'Invoke Ant'. However, 'Execute shell' method invokes the default Ant successfully in the slave machine.
Then, I had to use the 'Install Automatically' option in Jenkins to download and install Ant in the MAC slave to run the target. It works fine now.
Eventhough my issue is resolved, I am still curious why the default did not work with the option 'Invoke Ant'. Any of you know, please clarify.
Thank You All.
回答2:
Another alternative to "Install Automatically" is to use the Node Properties/Tools Locations option in the configuration screen for your slave node.
If you tick Tool Locations you will see you get an option to "List of tool locations"
There is a combo box which should list all the tools that may be used by your Jenkins slave.
For me, I have to specify the location of the ant, maven and jdk installations:
e.g.
Name: Maven-3.0.4
Home: C:\apache-maven-3.0.4
Clicking add lets you add others such as the JDK/ant etc. locations on the slave
回答3:
I was running into an issue where I was calling custom scripts that had ant commands within them based on certain conditions. I tried everything I found from various SO and other sites, but I was still left with the dreaded "ant: command not found" output in the console.
Since my scripts are based on different conditions, I needed to execute through the shell instead of the 'Invoke Ant' Jenkins option.
Exporting the Ant location via shell finally got ant to be recognized by Jenkins with the following added:
#bin/sh
export ANT_HOME=/your/path/apache-ant
export PATH=${PATH}:${ANT_HOME}/bin
I tried a lot of different solutions listed and this was the only solution that worked for me via the 'Execute shell'. All the configurations via Jenkins->Manage Jenkins->Configuration didn't fix the issue for some reason.
I was able to get the 'Invoke ant' option to work via @Vinoth S, but needed something a bit more customized.
回答4:
There are several things I do to make using third party stuff (like Ant) easier on my Mac:
First, I've setup /etc/paths
to include /usr/local/bin
:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
This means that each user will have /usr/local/bin
automatically setup as part of all users' PATH
. By adding /usr/local/bin
to the front of the PATH
, I can override default versions of commands:
$ /usr/bin/svn --version | head -1 # Default for Mac
svn, version 1.7.17 (r1591372)
$ /usr/local/bin/svn --version | head -1 # Newer version I added
svn, version 1.8.10 (r1615264)
$ svn --version | head -1 # The default one used
svn, version 1.8.10 (r1615264)
Now, I use ln -s
to link each program I want to execute to /usr/local/bin
:
$ ls -l /usr/local/bin/ant
lrwxr-xr-x 1 root wheel 29 Sep 3 14:27 /usr/local/bin/ant -> /opt/apache-ant/1.9.4/bin/ant
As you can see, all users now has the ability to execute ant
without having to modify their PATH
.
As for Jenkins Slaves, don't you configure the exact location of each tool?
When you create a slave, there's a tool location checkbox. Each tool you've defined in your Jenkins Configure System page can be given the actual PATH for that tool. Note that the (default) isn't one of them, so you have to define your jobs not to use the (default) version of that tool. This is the one in the PATH.
回答5:
I had the same issue here running a Jenkins slave on Windows 7 in a virtual machine. It couldn't find the environment variables. I started the JNLP via the launch button on one of the Jenkins project pages, which resulted in this issue. Later, I relocated the agent.jar file to my desktop in order to test executing from there, which may eliminate any r/w issues which a temp folder may have.
I started it with this command:
java -jar agent.jar -jnlpUrl http://your_ip_address_here:8080/computer/Win7/slave-agent.jnlp -secret your_secret_key_here -workDir "C:\Data\Jenkins"
This has solved the issue for me, which indicates some sort if r/w rights issues when being lauched via a webbrowser.