0

I'm setting up a Jenkins job in a salve machine and I'm new to Linux shell. Now I have a problem:

Logged in as jenkins(a user account set for Jenkins job), it execute ./gradlew, than it will start to download https://downloads.gradle.org/distributions/gradle-2.10-bin.zip, and it would fail because of the bad network, while it will start to run gradle normally if it executed "sudo ./gradlew".

Can someone help and tell me, how to make "./gradlew" the same as "sudo ./gradlew" as the user jenkins?

The shell scripts were from git for all, so I cannot modify it by adding "sudo".

Adding log in my real working scenario:

jenkins@reed:/local/jenkins/workspace/SV_TEST_/automation/robot$ id
uid=180(jenkins) gid=0(root) group=0(root)

jenkins@reed:/local/jenkins/workspace/SV_TEST_/automation/robot$ sudo ./gradlew webAPI:compileJava
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
:common:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7
:common:processResources UP-TO-DATE
:common:classes
:common:jar
:webAPI:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.7

BUILD SUCCESSFUL

Total time: 10.204 secs
jenkins@reed:/local/jenkins/workspace/SV_TEST_/automation/robot$ /local/jenkins/workspace/SV_TEST/automation/robot/gradlew -g /local/jenkins/.gradle -p /local/jenkins/workspace/SV_TEST/automation/robot clean 
Downloading https://services.gradle.org/distributions/gradle-2.10-bin.zip
...
Reed_Xia
  • 1,300
  • 3
  • 17
  • 29
  • 1
    It could be a permission issue. Take a look here if it can help you.http://stackoverflow.com/questions/33820638/travis-yml-gradlew-permission-denied – Gabriele Mariotti Apr 21 '16 at 09:07
  • 1
    It would help if you posted the console log of this error with context. –  Apr 21 '16 at 09:31
  • 3
    Do **not** add user jenkins to group root and do **not** use sudo to execute gradlew. Both are security risks to your server. Instead try to fix your setup so that a normal gradlew works. And even if you really have to use sudo (you most probably don't have to) don't add jenkins to the root group, but add to the /etc/sudoers file that user jenkins may execute this one command with sudo without supplying a password. But again, better fix your setup so that no sudo is necessary. As tony19 suggested, give us the console output, and maybe we are able to help you resolve your *real* problem. – Vampire Apr 21 '16 at 11:54

2 Answers2

0

Try replace the last line in gradlew with the follow:

exec sudo "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH"  org.gradle.wrapper.GradleWrapperMain "$@"
mainframer
  • 20,411
  • 12
  • 49
  • 68
hyongbai
  • 244
  • 1
  • 8
  • Thanks for the help, sorry to miss another detail in my question - the code was from git, I cannot modify since it's for all, I have to resolve it in local and deal with the permission problem. – Reed_Xia Apr 22 '16 at 01:12
0

Thankyou all for the kind answers, I find the way to resolve the problem :-)

I switched to root to check ~/.gradle, and found the files were quite complete, while ~/.gradle for jenkins had only one wrapper folder, so I copied all in ~/.gradle for root to the one for jenkins, than, it ran gradle normally without downloading as jenkins.

Reed_Xia
  • 1,300
  • 3
  • 17
  • 29