简体   繁体   English

GitLab CI:无法设置 JAVA_HOME

[英]GitLab CI: Unable to set JAVA_HOME

I am running git-lab server with Ubuntu 14 I am trying to compile a build on git-lab Ci but for some reasons I keep getting the same error over and over again:我正在使用 Ubuntu 14 运行 git-lab 服务器我正在尝试在 git-lab Ci 上编译构建但由于某些原因我一遍又一遍地收到相同的错误:

ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-openjdk-amd64/jre Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

No matter how I change the path of JAVA_HOME it is always the same results.无论我如何更改 JAVA_HOME 的路径,结果始终相同。 I have 4 folders inside the JVM folder:我在 JVM 文件夹中有 4 个文件夹:

java-8-oracle
java-7-openjdk-amd64
java-1.7.0-openjdk-amd64
default-java

But again no matter which directory I set the path to it is always the same result.但是同样,无论我将路径设置到哪个目录,结果总是相同的。

Here is my .gitlab-ci.yml file:这是我的.gitlab-ci.yml文件:

 before_script:
- export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
- export ANDROID_HOME="/opt/android-sdk"
- chmod +x gradlew

dev:  
  script:
  - ./gradlew assembleDebug

What could be the cause of this error?这个错误的原因可能是什么?

Try to change your .gitlab-ci.yml to this:尝试将您的.gitlab-ci.yml更改为此:

before_script:  
  - export ANDROID_HOME="/opt/android-sdk"
  - export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-amd64"
  - chmod +x gradlew

dev:  
  script:
    - ./gradlew assembleDebug

You can try removing chmod +x gradlew from before_script and move it to the main script :您可以尝试从before_script中删除chmod +x gradlew并将其移至主script

before_script:
- export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
- export ANDROID_HOME="/opt/android-sdk"

dev:  
  script:
  - chmod +x ./gradlew
  - ./gradlew assembleDebug

Reference: https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/#comment-4440925341参考: https ://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/#comment-4440925341

I know this issue might have been fixed already.我知道这个问题可能已经解决了。 But here is how I fixed mine.但这是我修复我的方法。

Use case:用例:

After I updated Java on my 3 environmennts(Dev, Staging, and Prod), everithing worked just fine on Dev and Staging.在我的 3 个环境(Dev、Staging 和 Prod)上更新 Java 后,一切都在 Dev 和 Staging 上运行良好。 But, for some reasons, the pipeline job in charge of deployment on production kept sending this error: "ERROR: JAVA_HOME is set to an invalid directory: C:/Program Files/Java/jdk1.8.0_171. Please set the JAVA_HOME variable in your environment to match the location of your Java installation."但是,由于某些原因,负责生产部署的管道作业不断发送此错误:“错误:JAVA_HOME 设置为无效目录:C:/Program Files/Java/jdk1.8.0_171。请在中设置 JAVA_HOME 变量您的环境以匹配您的 Java 安装位置。” My JAVA_HOME was set to the correct path.我的 JAVA_HOME 设置为正确的路径。

Fix: 0. make sur you Java_Home is properly set up.修复:0. 确保您的 Java_Home 已正确设置。 Fir windows users, something like C:/your jdk root folder/ (do not add /bin folder).对于 Windows 用户,类似于 C:/your jdk root folder/(不要添加 /bin 文件夹)。 1. Clear the runner caches in gitlab. 1.清除gitlab中的runner缓存。 2. Restart the gitlab-runner service on your deployment server. 2. 在您的部署服务器上重新启动 gitlab-runner 服务。

I hope that could help someone else.我希望这可以帮助别人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM