Nice programing

Jenkins에서 "gradle"프로그램을 실행할 수 없습니다.

nicepro 2020. 12. 11. 19:27
반응형

Jenkins에서 "gradle"프로그램을 실행할 수 없습니다.


Jenkins 용 Gradle 플러그인을 설치했습니다. 프로젝트를 빌드하려고하면 다음 오류가 발생합니다.

[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

$ gradle clean -b build/build.gradle명령 줄에서 작업 실행하면 예상대로 작동합니다.


나는 같은 문제가 있었고 나에게 문제가 프로젝트 구성의 gradle 버전이라는 것을 알았습니다. Default 로 설정 되어 있고 Manage Jenkins > Configuration Options 의 플러그인 구성에서 가리키는 gradle 버전으로 설정했을 때 gradle을 발견하고 제대로 작동했습니다.

이것은 디버깅하기 어려운 문제이며 다른 사람이 시간을 절약 할 수 있기를 바랍니다.


Solution Mastering_the_Object 는 저에게도 작동했다고 지적했습니다. 단계를 명확히하기 위해
Jenkins에 Gradle 플러그인을 설치하는 것만으로는 충분하지 않습니다.
Jenkins-> Manage Jenkins-> Configure Jenkins-> Configure system으로 이동해야합니다 .
"Gradle Installations"에서 이름을 입력하고 (프로젝트 구성에서 버전으로 표시됨) "자동으로 설치"를 선택하고 버전을 선택합니다. 그런 다음 프로젝트 구성에서 "Gradle 버전"을 선택할 수 있습니다.


Jenkins와 같은 CI 머신에서 Gradle을 실행할 때 Gradle Wrapper를 사용하는 것이 가장 편리합니다.

개발 컴퓨터에서 루트 프로젝트 디렉토리에 서서 다음을 실행하십시오.

gradle wrapper

그런 다음 결과 파일을 소스 제어 시스템에 체크인하십시오. 그 후에 Gradle 버전을 변경해야하는 경우 Jenkins 서버에 아무것도 설치할 필요가 없습니다. 다음과 같이 Jenkins 작업을 구성하십시오.

여기에 이미지 설명 입력

Gradle 사용자 가이드 에서 인용 :

프로젝트와 함께 래퍼를 배포하면 누구나 Gradle을 미리 설치하지 않고도 작업 할 수 있습니다. 더 좋은 점은 빌드 사용자가 빌드와 함께 작동하도록 설계된 Gradle 버전을 사용할 수 있다는 것입니다. 물론 이것은 서버에 구성이 필요하지 않기 때문에 지속적인 통합 서버 (예 : 프로젝트를 정기적으로 빌드하는 서버)에도 좋습니다.


Gradle 래퍼를 사용하여이 오류가 발생하여 다음과 같이 깨진 빌드를 수정할 수있었습니다.

  1. Go to Manage Jenkins -> Global Tool Configuration -> Gradle -> Add Gradle, give it a name
  2. Go to Jenkins -> (your job) -> Configure -> Build, choose "Invoke Gradle" and change the Gradle version from (Default) to the named version

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.

참고 URL : https://stackoverflow.com/questions/8646762/cannot-run-program-gradle-in-jenkins

반응형