Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins build error - Cannot run program "ant"

Tags:

jenkins

ant

I have build.xml set up to run a project to execute selenium test cases. I have mac computer and I can run ant from terminal. But when I try to run from jenkins I get following error. I have specified Ant home in Jenkins' config

/usr/local/Cellar/ant/1.9.4/libexec

I used homebrew to install ANT
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/Shared/Jenkins/Home/workspace/BaublebarTest"): error=2, No such file or directory at java.lang.ProcessBuilder.processException(ProcessBuilder.java:478) at java.lang.ProcessBuilder.start(ProcessBuilder.java:457) at hudson.Proc$LocalProc.<init>(Proc.java:244) at hudson.Proc$LocalProc.<init>(Proc.java:216) at hudson.Launcher$LocalLauncher.launch(Launcher.java:802) at hudson.Launcher$ProcStarter.start(Launcher.java:380) at hudson.Launcher$ProcStarter.join(Launcher.java:387) at hudson.tasks.Ant.perform(Ant.java:217) at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:770) at hudson.model.Build$BuildExecution.build(Build.java:199) at hudson.model.Build$BuildExecution.doRun(Build.java:160) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:533) at hudson.model.Run.execute(Run.java:1754) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:89) at hudson.model.Executor.run(Executor.java:240) Caused by: java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.enter code hereforkAndExec(Native Method) at java.lang.UNIXProcess.<init>(UNIXProcess.java:53) at java.lang.ProcessImpl.start(ProcessImpl.java:91) at java.lang.ProcessBuilder.start(ProcessBuilder.java:452) ... 15 more Build step 'Invoke Ant' marked build as failure Finished: FAILURE

like image 883
user2113098 Avatar asked Oct 16 '14 16:10

user2113098


People also ask

How do I run an Ant script in Jenkins?

Go to Manage Jenkins -> Manage Plugins -> Available and search for Ant Plugin . After it's installed, go back to your job configuration and select a new build step Invoke Ant .

Can Jenkins execute Ant project?

Jenkins Ant and the web UI To take advantage of the Jenkins Ant plugin, create a freestyle project named 'Apache Ant and Jenkins Build Job Example. ' Run the Jenkins Ant build job and the source code will be pulled from GitHub, the tasks will run, and the application will be compiled, tested and packaged as a WAR file.

How do I run Ant in Jenkins pipeline?

you can use ant wrapper in Jenkins`s pipeline groovy script. Remember to configure the ant tool in the Jenkins "Global Tool Configuration" with the same name "LocalAnt". for the sh "ant build" do I need to put the path to the build xml file or will simply typing `"ant build" work?

Is Jenkins supports Ant script?

Jenkins integrates with multiple build tools such as Maven, Gradle, and Ant.


2 Answers

First, the proper way

Jenkins will install Ant (and other tools for you). On the Global Configuration (Manage Jenkins), configure Ant installation, by selecting the version and the source.

Then, when you run an Ant build step, you can choose a version, either default or the one you've just configured. When the build is executed, Jenkins will download, install, and configure that particular version for you (within Jenkins only), without affecting the rest of the OS. The installation only needs to happen once per node, and after that it's quick.

The default

That default version is a fallback that Jenkins uses when you haven't configured a proper version to use. It tries to use whatever is available on command line, simply by executing ant from current working directory.

You said it works for you when you just type ant on command line, but you've got to realize that Jenkins runs under jenkins user, not your logged in user, and things like ANT_HOME and proper path to Ant is probably configured specifically for your user.

So to fix your issue, either use the proper way with Jenkins doing the tool installation, or properly configure the tool on OS level for jenkins user.

You can start by typing:
sudo su jenkins
ant
And seeing if that works from within jenkins user

like image 52
Slav Avatar answered Oct 06 '22 23:10

Slav


I am not using terminal for jenkins, but I was getting the same error. Changing Ant version from default to Ant fixed the errors.

like image 31
Yunus Nedim Mehel Avatar answered Oct 06 '22 23:10

Yunus Nedim Mehel