Jenkins_Execution of gradle script throws a permission denied error - jenkins

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.

Related

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

grails 3 run-app fails due to file permissions set by perforce VCS

TLDR:
I have a Grails 3 project. The run-app command was working fine. Then I checked it into Perforce. Now run-app fails.
DETAILS:
Grails Version: 3.1.1
Groovy Version: 2.4.5
JVM Version: 1.8.0_91
Gradle 2.13
% grails clean
BUILD SUCCESSFUL
% grails run-app
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':processResources'.
Could not copy file '/Volumes/Neo/singram/work/code/depot/dvdco/webapplications/nightcrawler/grails-app/i18n/messages.properties' to '/Volumes/Neo/singram/work/code/depot/dvdco/webapplications/nightcrawler/build/resources/main/messages.properties'.
GUESS at cause:
Perforce, when a file isn't checked out for editing, will make that file non-writable (chmod a-w). As best I can tell, run-app invokes gradle's processResources which successfully copies the file in question once, then seemingly attempts to copy it again during the same build cycle and fails because thew newly copied file is not writable so it cannot be overwritten with a copy of itself.
WORK-AROUND
The run-app command succeeds if I check out the whole project for editing first. Don't really want to have to do this as it introduces opportunity for error during check-ins.
QUESTION:
Is there a better way than my work-around? Why is gradle's processResources copying the same files more than once? Is there some sort of hook into processResources or run-app that I can use to "chmod -R u+w build" ?
A couple of options, methinks. Either 1) change the filetype(s) (if Perforce-controlled) to +w to make them writable; or 2) change the workspace spec to include the "allwrite" option to make all files writable. –

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.

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