Try setting the GRADLE_USER_HOME variable to a folder that you have valid access to. Then this error will disappear.
For example: I ran into the same problem today when I was doing gradle clean on a new slave machine.
My version of Gradle was 2.3.
With --stacktrace, I found out that he was trying to create a .gradle folder to store Gradle cache data (while I was calling Gradle to run a clean task on the slave), and he was trying to create this folder in / some / location / where / gradle / exists OR some / path / location / xxx / yyy, where the user who ran Gradle on the slave computer did not have real write access (create folder / files).
that is, the user I used to connect from a Jenkins computer to a subordinate did not have write permission to touch / mkdir in the default folder (where Gradle thought, okay, I have to create a .gradle folder here).
To fix this, I added the aforementioned GRADLE_USER_HOME variable in the slave variable section of GRADLE_USER_HOME . Now that I have valid access in my home directory, I was fine.

Environment:
GRADLE_USER_HOME=~/gradle_2_3_cache/.gradle
solved a problem.
You can also set it to ~ / .gradle. But I put it under the user folder in my ~ home directory (gradle_2_3_cache). This will help me if I have another slave running on the same slave computer, but with a different version of Gradle for version 2.5, etc., And if I need the .gradle cache for version 2.3 and 2.5 / x in separate folders.
Arun sangal
source share