I am trying to set up a Jenkins job to build the next big Android app! I've got the Android SDK installed and that part seems to be working fine. I've got Gradle Plugin v1.24 installed on Jenkins and now I think I'm trying to figure out how to get Gradle actually working.
First attempt was to have Jenkins download a specific version automatically from gradle.org. I'm trying to pull v2.2.1 because that seems to be the version my Android app builds with locally. When I do that I get this error in my Jenkins job:
[Gradle] - Launching build.
Invalid tool ID 2.2.1
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
Build step 'Invoke Gradle script' marked build as failure
I tried many different versions but could not get that working. So, next was to tell Jenkins where to download Gradle from. I gave it this location:
https://services.gradle.org/distributions/gradle-2.2.1-bin.zip
I get a different error when building but still not too sure what to do.
[Gradle] - Launching build.
[Journeyman-Android] $ gradle clean build
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/var/lib/jenkins/workspace/Journeyman-Android"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.Launcher$ProcStarter.join(Launcher.java:389)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:262)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:116)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
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:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
I tried to see what I can do with the Jenkins CLI but that fails for me too. We use Jenkins to build/deploy several other projects successfully so this is a working Jenkins installation.
Does anyone have any pointers or suggestions for what I may need to do?
Update (still failing)
I am able to build my app manually but navigating to the root of my project in the jenkins workspace and executing
./gradlew assemble
Finally figured it out. I needed to update my jenkins job to use the Gradle wrapper instead of a specific Gradle version. Once I did that I had a few more errors to sift through but they were all very informative and gave me the information I needed to resolve them.
I downloaded the Gradle. Extracted to some place.
In Jenins > Manage Jenkins > Gradle
Unchecked the install automatic.
Set the path to gradle home, (Ex: C:\Graddle\gradle-2.1).
Probelm resolved.
For Jenkins running on linux:
download gradle zip file
cd /opt/
wget https://services.gradle.org/distributions/gradle-2.10-all.zip
unzip
unzip gradle-2.10-all.zip
visit jenkins website
Jenkins > Manage Jenkins > Configure System > Gradle > Gradle installations
uncheck Install automatically, set 2.10 to name, set /opt/gradle-2.10 to GRADLE_HOME.
click your job
Configure > Build > Invoke Gradle script
select Invoke Gradle, select 2.10 in Gradle Version dropdown list.
If one previously configured the build with Invoke Gradle script
option and selected a specific Gradle Version
(say 2.4 for example), he initiated the build but later switched to Use Gradle Wrapper
option without resetting the Gradle Version
value back to Default
. Jenkins would issue the
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
It is a jenkins' bug as documented by this post.
The workaround is to reset Gradle Version
to Default
before swithcing to Use Gradle Wrapper
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With