Jenkins and CMake: permission errors - jenkins

I installed Jenkins, I'm new to it. Made a user, installed the CMake plugin. I'm trying to compile a simple project just to get started but I cannot even do that.
After complaining of not being able to open some files (like build/CMakeFiles/CMakeOutput.log), at the end of the output it says:
-- Configuring incomplete, errors occurred!
CMake Error: Cannot open file for write: /home/username/development/csa/build/CMakeCache.txt.tmp
CMake Error: : System Error: Permission denied
CMake Error: Unable to open cache file for save. /home/username/development/csa/build/CMakeCache.txt
CMake Error: : System Error: Permission denied
Build step 'CMake Build' marked build as failure
Finished: FAILURE
To me this is clearly a permissions issue. The build directory is empty, it has not done anything. I created a user, started jenkins and either of the following had no effect on the output:
sudo /etc/init.d/jenkins start --user jenkins
sudo /etc/init.d/jenkins start --user username
sudo /etc/init.d/jenkins start
I'm not even trying to compile the code, just trying to build the cmake files... my configuration is like this: (as simple as possible)
I did add a working directory which is in my home folder so I do have permissions for it.
EDIT: I changed the ownership of the build folder to jenkins, created a user group called jenkinsusers, added myself and jenkins to the group, and gave the group read/write permissions. It appears to work now. But I'm not sure this is the standard way to do this...

So I'm not sure this is the right way but this is how I did it: I changed the owner of the directory to jenkins.
The workspace folder is under my home directory (~/myproject/build). That's probably the issue. The compiling gets done using catkin_make, a tool from ROS.

Related

I can't build and install a project with Cmake on Jenkins

I really need some help to build a simple project with Cmake with Jenkins.
I downloaded the Cmake plugin on Jenkins.
I configured it in the job :
and in Global Tool Configuration :
But then it doesn't work. Here are the end of the logs before the Jenkins build fails :
+ ls
CMakeLists.txt
MathFunctions
TutorialConfig.h.in
build
tutorial.cxx
[build] $ cmake /var/jenkins_home/workspace/Project
ERROR: Cannot run program "cmake" (in directory "/var/jenkins_home/workspace/Project/build"): error=2, No such file or directory
Build step 'CMake Build' marked build as failure
Finished: FAILURE
I don't understand why there is no proper step-by-step tutorial to create something that common as a Cmake build with Jenkins.
In the end, I managed to pull it off.
I uninstalled the Cmake plugin which seems to be useless apparently...
And I simply installed Cmake manually on the Jenkins container.

Gradle build in docker jenkins slave

I am trying to create a jenkins slave for building gradle lambda projects. Jenkins slave is throwing the below error while building the project.
Exception in thread "main" java.lang.RuntimeException: Could not create parent directory for lock file /gradle/wrapper/dists/gradle-4.2.1-bin/dajvke9o8kmaxbu0kc5gcgeju/gradle-4.2.1-bin.zip.lck
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:43)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
/home/jenkins/workspace/ddoa-subprod/lf-security-gateway2/lf-security-gateway2
FAILURE: Build failed with an exception.
* What went wrong:
Failed to load native library 'libnative-platform.so' for Linux amd64.
Please help me in understanding the issue and let me know how to fix the same.
To fix this error: What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64. do the following:
Check if your Gradle cache (**~user/.gradle/**native folder exist at all or not).
Check if your Gradle cache (~user/.gradle/native folder exist and the file in question i.e. libnative-platform.so exists in that directory or not).
Check if the above folder ~user/.gradle or ~/.gradle/native or file: ~/.gradle/native/libnative-platform.so has valid permissions (should not be read-only. Running chmod -R 755 ~/.gradle is enough).
IF you don't see native folder at all or if your native folder seems corrupted, run your Gradle task ex: gradle clean build using -g or --gradle-user-home option and pass it's value.
Ex: If I ran mkdir /tmp/newG_H_Folder; gradle clean build -g /tmp/newG_H_Folder, you'll see Gradle will populate all the required folder/files (that it needs to run even before running any task or any option) are now in this new Gradle Home folder (i.e. /tmp/newG_H_Folder/.gradle directory).
From this folder, you can copy - just the native folder to your user's ~/.gradle folder (take backup of existing native folder in ~/.gradle first if you want to) if it already exists -or copy the whole .gradle folder to your ~ (home directory).
Then rerun your Gradle task and it won't error out anymore.
Gradle docs says:
https://docs.gradle.org/current/userguide/command_line_interface.html
-g, --gradle-user-home
Specifies the Gradle user home directory. The default is the .gradle directory in the user’s home directory.
Note: using gradle <sometask> -g <a_dynamic_folder_ex_jenkins_workspace> will always work as Gradle will create fresh .gradle cache in that -g defined folder, but doing this, it'll not reap the true benefit of Gradle's cache concept.
If you are using a version 3.4 if Gradle, then it could possibly be this issue.
To fix it, you can try to update your Gradle distribution to version 3.5 or higher, where this issue was solved.
I ran the command as sudo and it went through fine

Jenkins_Execution of gradle script throws a permission denied error

In jenkins iam facing an error when i trigger the gradle task.
When i execute the below shell
cd /home/cucumberBdd
./gradlew cucumber
I got this error ".gradle/1.8/taskArtifacts/cache.properties.lock (Permission denied)"
Below are the configurations:
Os-Ubuntu
CI-Jenkins
Buildtool:Gradle
Script: gradle script
I have installed and mentioned the gradle version in the manage jenkins.
One thing which i noticed is in jenkins the above command + whoam i gives jenkins name but the project folder writes are with system user.Can anyone tell me please how to avoid this error
You should not put .gradle in the version control at all, only the gradle directory (without the dot) needs to be versioned. Everything in .gradle is just caching stuff and can be safely deleted and recreated.

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.

Jenkins building Xcode - getting build error "permission denied"

I'm trying to get a phonegap project building on our Jenkins build server and I'm getting a permission denied error. Keep in mind, this is my first experience with Mac OS X.
The build output in Jenkins is telling me this:
/bin/sh -c \"/Users/Shared/Jenkins/Home/jobs/myMobile\ -\ iOS/workspace/build/TDE.build/Release-iphoneos/TDE.build/Script-304B58A110DAC018002A0835.sh\"
/Users/Shared/Jenkins/Home/jobs/myMobile - iOS/workspace/build/TDE.build/Release-iphoneos/TDE.build/Script-304B58A110DAC018002A0835.sh: line 2: cordova/lib/copy-www-build-step.sh: Permission denied
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Copy\ www\ directory build/TDE.build/Release-iphoneos/TDE.build/Script-304B58A110DAC018002A0835.sh
(1 failure)
Build step 'XCode' marked build as failure
Finished: FAILURE
Googling this, I found a SO post saying to run the chmod 755 command on this .sh file, but that still didn't fix anything. What else should I be doing to get this file to be able to execute/copy or whatever it's doing?
Edit: Is my actual permission issue for this file:
line 2: cordova/lib/copy-www-build-step.sh: Permission denied
Or is it the Script-.... file?
Added permissions on the ...copy-www-build-step.sh file and that fixed THIS build error. On to the next...
In order for these permissions to stay even after doing a full-checkout from SVN via Jenkins, find the copy-www-build-step in your source control. View the properties for the file, and add svn:executable.
This fixes it so you don't have to keep updating the permissions if you do a full checkout for every build.
I get the answer... I have to change the file permissions.. sudo chmod 777 copy-www-build-step.sh
just move to the platforms/ios/cordova/lib and execute the above command.

Resources