Jenkins build error - Cannot run program "ant" - 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

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

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

Related

How to integrate Gauge with Jenkins

I am somewhat familiar with Gauge testing tool and am now working on executing it via Jenkins.
First: i set gauge --version in the "Execute Windows Batch Command" field. This was the output:
Started by user anonymous
Building in workspace C:\jenkins\workspace\Run_Gauge_Test
[Run_Gauge_Test] $ cmd /c call C:\WINDOWS\TEMP\hudson8329964667758110371.bat
C:\jenkins\workspace\Run_Gauge_Test>gauge --version
Gauge version: 0.6.2
Plugins
-------
No plugins found
Plugins can be installed with `gauge --install {plugin-name}`
C:\jenkins\workspace\Run_Gauge_Test>exit 0
Finished: SUCCESS
Compare this to the output I get if I run Gauge directly in command line:
C:\jenkins\workspace\Run_Gauge_Test>gauge --version
Gauge version: 0.6.2
Plugins
-------
html-report (2.1.1)
java (0.5.1)
xml-report (0.1.3)
So i put the same command in a batch file and ran it only to get the "no plugins found" message again.
As a last option I ticked the Use custom workspaceand set my directory to a folder where I usually run gauge tests from command line but still it is "no plugins found"
Then i tried running it as a shell command. Output:
Started by user anonymous
Building in workspace C:\jenkins\workspace\Run_Gauge_Test
[Run_Gauge_Test] $ sh -xe C:\WINDOWS\TEMP\hudson211231385407124893.sh
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "sh" (in directory "C:\jenkins\workspace\Run_Gauge_Test"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
(truncated)
at hudson.model.Executor.run(Executor.java:404)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 16 more
Build step 'Execute shell' marked build as failure
Finished: FAILURE
Of course, I am going to actually run the gauge tests(and it doesnt work) rather than just get the version; but I thought it would be simpler to troubleshoot why it doesnt get plugin details correctly.
Any clues?
Gauge plugins should be installed via user/admin account with which the Jenkins agent executes commands. Have a look at following doc for more on integrating with GoCD and few other CI tools.
https://docs.gauge.org/latest/howto/index.html#tutorials
Long answer:
Currently, Gauge executable is installed at system level. Whereas Gauge plugins(language runners, reporting plugins etc) are installed at a user level. So if you install plugins as one user manually and on CI if task is run against different user, gauge will not be able to find plugins.
To fix this, you should run plugin install commands from the account with which CI runs. Or as Srikanth's comment says, you can have gauge --install-all task in pipeline. This installs all required plugins on the fly.
I suspect that you are installing and using Gauge as different users. As with a lot of CI tools, often the tasks are executed under a different users than one would use to log into the agent.
Currently the way Gauge works is: gauge.exe is available at a system level. However, the plugins are installed at a user level.
So if you login as user1 and do gauge --install java, gauge --version will list java as a plugin only when you are logged in as user1.
This is also true if you are running your CI agent under a local system account.
One way you can address this is if you include setup as a task in your pipeline, i.e. have a gauge --install-all from your project root before attempting to run your specs.

P4 command line client in Jenkins issues on OSX

I've been scratching my head on this issue but haven't found a way around it. I've installed Jenkins on my OSX v10.8.4 using the Jenkins 1.571 installer from the Jenkins website.
It gets installed by default in /Users/Shared/Jenkins/Home folder.
I want to use Jenkins to act as a CI server for my iOS code residing on my company's perforce server. For this I created a user(matching to that of my perforce user along with the same password)on my OSX box. I also copied the P4 command line to /usr/local/bin and correctly setup the P4PORT to point to my perforce server settings. So far so good.
I verified that I was able to connect to my perforce server from command line by using the p4 login command, and it worked successfully.
I then installed the perforce plugin from Jenkins Manage plugins option (https://wiki.jenkins-ci.org/display/JENKINS/Perforce+Plugin).
Now when I create a new job and specify the settings correctly in the perforce plugin piece of the jenkins job, I always get these errors:
Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/iosbuild/workspace
Using master perforce client: ios-jenkins
[workspace] $ p4 workspace -o ios-jenkins
Caught exception communicating with perforce. Could not run perforce command.com.tek42.perforce.PerforceException: Could not run perforce command.
at hudson.plugins.perforce.HudsonP4DefaultExecutor.exec(HudsonP4DefaultExecutor.java:90)
at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTemplate.java:331)
at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTemplate.java:301)
at com.tek42.perforce.parse.Workspaces.getWorkspace(Workspaces.java:61)
at hudson.plugins.perforce.PerforceSCM.getPerforceWorkspace(PerforceSCM.java:1615)
at hudson.plugins.perforce.PerforceSCM.getPerforceWorkspace(PerforceSCM.java:1576)
at hudson.plugins.perforce.PerforceSCM.checkout(PerforceSCM.java:892)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1252)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:624)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:530)
at hudson.model.Run.execute(Run.java:1732)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:234)
Caused by: java.io.IOException: Cannot run program "p4" (in directory "/Users/Shared/Jenkins/Home/jobs/iosbuild/workspace"): 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.(Proc.java:244)
at hudson.Proc$LocalProc.(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:780)
at hudson.Launcher$ProcStarter.start(Launcher.java:360)
at hudson.plugins.perforce.HudsonP4DefaultExecutor.exec(HudsonP4DefaultExecutor.java:81)
... 14 more
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.(UNIXProcess.java:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 19 more
ERROR: Unable to communicate with perforce. Could not run perforce command.
Finished: FAILURE`
First I specified the perforce jenkins plugin to create the workspace for me and also let jenkins to manage my views, but I still got the same above error.
Following is my view map:
//depot/rombay/MarketingApplication/iOS/ianywhere/... //ios-jenkins/depot/rombay/MarketingApplication/iOS/anywhere/...
I then created a workspace using the p4v client, and then deselected letting jenkins create my workspaces and manage my views. The view map remains the same. However, I still get the same error.
My hunch is that since Jenkins is installed in the shared folder it's not able to execute the p4 command. However, I tried doing that and it opened up the clientspec in vi for me, which is I guess the expected behavior, but I still don't understand as to why it says that it can't find the p4 program to work for me.
Any help here would be deeply appreciated as I've run out of ideas as to what could possibly be I doing wrong.
No softlinks are required. Check if you have updated the Global Settings for p4. Manage Jenkins->Global Settings

Jenkins cannot run program "phing" - Phing command execution failed

I'm new to jenkins and phing and having what appears to be a basic error with jenkins not being able to run my phing commands. Console log of my failed build is below. I only have one install of phing so I understand I don't need to "configure the job to choose one", I've also tried to add a PATH to my jenkins global environment variables and restarted Jenkins after adding the variables and still no go. I already have Phing in my local PATH as I can invoke the phing command anywhere. I'm also able to invoke the same phing command that jenkins does from terminal and the the build finishes. However, Jenkins' Build Now always fails. Any help would be great! thanks :)
Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/php-template/workspace
Fetching changes from the remote Git repository
Fetching upstream changes from ssh://git#mystash.server:7999/myproject/myrepo.git
Checking out Revision 8fb6f843d6fd232cdde1684e18c455cef6f20460 (origin/master)
looking for '/Users/Shared/Jenkins/Home/jobs/php-template/workspace/build.xml' ...
use '/Users/Shared/Jenkins/Home/jobs/php-template/workspace' as a working directory.
[workspace]
$ phing -buildfile /Users/Shared/Jenkins/Home/jobs/php-template/workspace/build.xml clean try_ParallelTasks -logger phing.listener.DefaultLogger
FATAL: command execution failed.Maybe you need to configure the job to choose one of your Phing installations?
java.io.IOException: Cannot run program "phing" (in directory "/Users/Shared/Jenkins/Home/jobs/php-template/workspace"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
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$ProcStarter.join(Launcher.java:360)
at hudson.plugins.phing.PhingBuilder.perform(PhingBuilder.java:215)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:804)
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:585)
at hudson.model.Run.execute(Run.java:1670)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)
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:135)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 15 more
Build step 'Invoke Phing targets' marked build as failure
To be clearer, as Cweiske pointed out, Jenkins fails the build because it cannot find the correct phing executable, as it looks for it in the wrong path (the one in the workspace).
Anyway, Jenkins search for that executable in other paths too, as the one you cited: "in my local PATH as I can invoke the phing command anywhere".
The problem with Your Local Path is that it is the YOUR and not the Jenkin's one. As Jenkins act on your Mac with its own user (jenkins, created during the installation process), so it cannot use Your Local Path.
Understood the problem, there is more than one possible solution (and i've tried them one by one with no success!), but the simpler (and the one that finally works!) is the "symlinking".
A note: please, take care of the difference between various types of "links" on Mac: SymLinks are different and not equals to Aliases or to Hard Links (http://macs.about.com/od/faq1/f/What-Are-Aliases-Symbolic-Links-And-Hard-Links-In-Mac-Os-X.htm).
Coming back, as in the usr/bin folder there are executables that each user on the mac can use, let's create a symlink into this folder to the executable you use every time, the one included in the folder in Your Local Path.
From Terminal, go to the usr/bin folder. Use the command "cd" to change the current directory and to go to the top of the root use something like:
> cd ../
With the command "pwd" you can see the complete path to the directory in which you currently are, and with the "ls" command you can list all the files and folders in it: use them to guide yourself in the folders tree.
So, assuming you already are in the usr/bin folder and assuming you are using MAMP as webserver, the command is:
> ln /Applications/MAMP/bin/php/php5.5.10/bin/phing ./phing
As you can see, the first parameter is the path to the executable you want to symlink, and the second parameter is the path to the folder in which you want to create the symlink. Don't forget to append the name of your new symlink!
Once done, try again to build with Jenkins: all should work well now... i hope!
Some troubleshooting:
1) You created the symlink in the wrong folder: use "rm" to remove a file
2) You haven't the right permissions: use "sudo" to act as a super admin
> sudo ln /Applications/MAMP/bin/php/php5.5.10/bin/phing ./phing
The directory in which the phing script is installed is not in $PATH of the jenkins user.
Symlink it into /usr/bin/, and you should be set.
From the following error message
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:248)
at java.lang.ProcessImpl.start(ProcessImpl.java:134)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
I got this "IOException when starting a process"
It seems like ProcessBuilder doesn't use the env variable PATH, so it can't find find phing
What I did is I removed Invoke Phing targets and added the Build as Execute Shell, and in Command I added /usr/local/bin/phing. and that is working for me.

Cannot run program "gradle" in Jenkins

I've installed the Gradle plugin for Jenkins. When I try to build the project I get the following error:
[workspace] $ gradle clean -b build/build.gradle
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/Users/Shared/Jenkins/Home/jobs/test/workspace"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:707)
at hudson.Launcher$ProcStarter.start(Launcher.java:338)
at hudson.Launcher$ProcStarter.join(Launcher.java:345)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:201)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:97)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:695)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)
at hudson.model.Run.run(Run.java:1404)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:238)
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:53)
at java.lang.ProcessImpl.start(ProcessImpl.java:91)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
Running the task $ gradle clean -b build/build.gradle from the command line works as expected.
I had the same issue and found that the problem for me was the gradle version in the project configuration. It was set to Default and when I set it to the gradle version I was pointing to in the plugin configuration in the Manage Jenkins > Configuration Options, It found gradle and worked properly.
This is a difficult issue to debug and I hope this saves someone else some time.
Solution Mastering_the_Object pointed out worked form me too, just to clarify steps there:
just installing Gradle plugin in Jenkins is not enough, you must also go to:
Jenkins->Manage Jenkins->Configure Jenkins->Configure system.
Under "Gradle Installations" type in name (it appears as version in project configuration), check "Install automatically" and select version. Then you can select that "Gradle version" in project configuration.
I was getting this error using the Gradle wrapper, was able to fix my broken build as follows:
Go to Manage Jenkins -> Global Tool Configuration -> Gradle -> Add Gradle, give it a name
Go to Jenkins -> (your job) -> Configure -> Build, choose "Invoke Gradle" and change the Gradle version from (Default) to the named version
When running Gradle on a CI machine such as Jenkins, it's most convenient to use the Gradle Wrapper.
On your development machine, stand in your root project directory and run
gradle wrapper
Then, check in the resulting files into your source control system. After that, you don't have to install anything on your Jenkins server if you need to change Gradle versions. Just configure your Jenkins job like this:
Quoting from the Gradle User Guide:
By distributing the wrapper with your project, anyone can work with it
without needing to install Gradle beforehand. Even better, users of
the build are guaranteed to use the version of Gradle that the build
was designed to work with. Of course, this is also great for
continuous integration servers (i.e. servers that regularly build your
project) as it requires no configuration on the server.
The jenkins can not find the gradle executable. I have never made gradle wrapper to work. Please follow the following steps:
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
It works for my jenkins installation.
ps. I answer this old question, because it is a common issue when setting up gradle with jenkins. I have spent some time trying to make the gradle wrapper work without success before.
Used both #Skarab & a number of other solutions here to get it to work.
Download gradle ( http://gradle.org/downloads),
unpack it to, e.g., /usr/local/lib/gradle ,
open /etc/profile and add the following two lines:
export GRADLE_HOME=/usr/local/lib/gradle
export PATH=$PATH:$GRADLE_HOME/bin
Then under Manage Jenkins > Configure system > Gradle, defined GRADLE_HOME and gave that gradle installation a name
Then, {this could be a bug} for the project, change gradle version from Default to the one I defined above
As others have noted, this is because Jenkins can't find the gradle executable.
None of the published solutions worked for me, but I was able to fix the problem by adding the gradle bin dir to the path set in the .bashrc for the build account on the build slave. Modifying the .profile failed, and setting PATH in the jenkins node configuration also failed.
Some posts will suggest setting the gradle path in the tools menu, but no gradle entry was available there either (perhaps due to regressions / design changes in the gradle plugin?).
In any case, the best test I found (short of running the build again and watching for failure) was to run env over ssh:
ssh <host> env
and check the PATH variable defined that way; if gradle isn't in that path, you probably won't be able to run it from jenkins.

Sonar plugin not working for projects that use ANT as a build script

Problem
I have just installed the Sonar Jenkins plugin. I went into my configured job (a free style job) that produces a WAR file artifact through an ANT build and did as follows:
Check the Sonar checkbox. (No problems here)
Configure the install dir of sonar (No problems here)
Checked the checkbox that states: "Check if this project is NOT built with maven 2" (I am confused here)
I have checked that box because I am not using maven for build, I am using ANT but it still asked me for required properties that resemble a lot MVN such as: Organization id, project id, project name, project version, source directories... etc..
So I have filled those as well. When I click the play button "Build Now" the build seems to be running fine as it always had prior to sonar installation but it fails at the very end because its trying to execute MAVEN.
See as follows:
$ mvn -f /root/.jenkins/jobs/HRDA/workspace/pom.xml -e -B sonar:sonar
FATAL: command execution failed
java.io.IOException: Cannot run program "mvn" (in directory "/root/.jenkins/jobs/HRDA/workspace"): java.io.IOException: error=2, No such file or directory
Questions
Why is Sonar trying to execute Maven if I have checked the box that said check this box if you do NOT use Maven 2?
Can I make use of this Sonar plugin if my apps are built with ANT, GANT, GRADLE?
Do I have to reconvert my apps to use MVN builds?
Thanks,
- Dario
Like Oers suggested on my question comments if you are using ANT as a build script in your CI server (Jenkins in my case) you will have to use the SONAR-ANT-TASK to generate Sonar reports, do as follows:
Download MySQL or any other Sonar supported RDBMS such as Postgres, Oracle, etc..'
Download and Install sonar server.
go to (sonar installation folder)/extras/database/mysql and run the create_database.sql script.
I had to run an extra sql statement in my case using mysql, you can see here Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
Start Sonar by typing ./sonar.sh start
Add the sonar ant task to your build script. You can follow this template http://docs.codehaus.org/display/SONAR/Analyse+with+Ant+Task+1.0
DO NOT check the sonar check box in your Configure screen if you have the Hudson Sonar plugin for installed, as this plugin only works with Maven projects.
Click the "Build Now" button. If everything above has been done correctly you should be able to see the reports at http://ipaddressofmachinesonarisinstalled:9000/
Hope this helps,
-Dario

Resources