P4 command line client in Jenkins issues on OSX - jenkins

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

Related

Unable to delete directory when Invoking Ant only on slave node

Build failed on slave server only due to unable to delete only Jar directory.
We are trying to load balance the Jenkins and hence launch the slave node, where we mounted workspace of Master to slave node. We are getting the following error while doing ant clean from the /var/lib/jenkins/workspace/TEST/. However, this is working fine on Master and giving error only on Slave node. Tried upgrading ant version on Slave but no luck. Also check permission and its fine. How can i solve this.
/var/lib/jenkins/workspace/TEST/build.xml:115: Unable to delete directory /var/lib/jenkins/workspace/TEST/jar
Adding to it if there are files inside Jar then only it fails. However, if Jar is empty then it works fine.

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

Copy code from Perforce to Dev Server using Jenkins

I would like to use Jenkins to copy newly commited code from Perforce to a Dev Server.
When the project is run in Jenkins it will detect all changes in Perforce workspace and build+deploy code to specific server.
I am using Jenkins on Windows box.
I have installed Jenkins and the Perforce plugin on Windows 7 laptop currently for testing/trying.
The configurations have all been setup,
In Configure System - > Perforce -> Path to Perforce exe is set to C:\Program Files\Perforce\p4v.exe, which is the right path.
In the project under Source Code Management -> Perforce I have setup
hostname:port,
username and password,
workspace,
client view type to View Map with location.
When I try to build the project I get an exception:
Started by user anonymous
Building in workspace <http://localhost:8080/job/Test3/ws/>
Using master perforce client: Jenkins_Test [workspace] $ "C:\Program Files\Perforce \p4v.exe" workspace -o Jenkins_Test Caught exception communicating with perforce. No output for: C:\Program Files\Perforce\p4v.exe workspace -o Jenkins_Test com.tek42.perforce.PerforceException: No output for: C:\Program Files\Perforce\p4v.exe workspace -o Jenkins_Test at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTempl ate.java:408) at com.tek42.perforce.parse.AbstractPerforceTemplate.getPerforceResponse(AbstractPerforceTempl ate.java:301)
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:1320)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:609)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:518)
at hudson.model.Run.execute(Run.java:1688)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)
ERROR: Unable to communicate with perforce. No output for: C:\Program Files\Perforce\p4v.exe workspace -o Jenkins_Test
What is wrong and how do I accomplish my goals (Jenkins will detect all changes in Perforce and build+deploy code to specific server.)?
You said that "Path to Perforce exe is set to C:\Program Files\Perforce\p4v.exe".
p4v.exe is the GUI tool for Perforce.
You probably want the command line tool for Perforce, which is 'p4.exe'.
See if you have 'p4.exe' in the same directory, and change your configuration to point to p4.exe instead of p4v.exe.

CloudBees Back-up Plugin failing

Below is the error message I'm receiving. The master is running on OpenSUSE and my Jenkins version is "Jenkins ver. 1.466.12.1 (Jenkins Enterprise by CloudBees 12.11)".
I've verified that I can create a file on the linux box in /mnt/jenkinsbackup. Is this a user permission problem?
Building on master in workspace /var/lib/jenkins/jobs/Jenkins Backup/workspace
java.io.FileNotFoundException: /mnt/jenkinsbackup/backup-Jenkins Backup-19.tar.gz (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:209)
at java.io.FileOutputStream.(FileOutputStream.java:160)
at com.infradna.hudson.plugins.backup.store.LocalFileStore$1._backup(LocalFileStore.java:50)
at com.infradna.hudson.plugins.backup.store.BackupFile.backup(BackupFile.java:25)
at com.infradna.hudson.plugins.backup.BackupBuilder.perform(BackupBuilder.java:95)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:710)
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:480)
at hudson.model.Run.run(Run.java:1438)
at hudson.model.Build.run(Build.java:110)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)
Build step 'Take backup' changed build result to FAILURE
Finished: FAILURE
EDIT: I forgot to mention that I am running jenkins as a daemon and not as a user.
The permission problem stemmed from the mounted network folder. Only root had permission to write to it. One suggestion I found on the internet was to change the ownership of the folder to jenkins:nogroup (since that is what the Jenkins master is running as), but you can't do that to a mounted folder.
But that led me to changing the permissions when mounting the folder in the first place. I learned I could do this:
mount -t cifs //network_folder_path/jenkins /mnt/jenkins -o username=USERNAME,password=XXXX,dir_mode=0777,file_mode=0777
That mounted the folder with write permissions for everyone and the job was able to run.
The stack trace does say permission error - so perhaps the jenkins app is running as a different user to the one you verified can read and write to that directory?

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.

Resources