繁体   English   中英

无法设置JAVA_HOME GitLab CI

[英]Unable to set JAVA_HOME GitLab CI

我在2个码头工人上运行gitLab和gitLab runner。

当我推送我的代码时,我的管道启动但我有这个错误:

Running with gitlab-runner 11.9.1 (de08a4bb)
  on bf23c668df26 78rP5HeK
Using Docker executor with image alpine:latest ...
Pulling docker image alpine:latest ...
Using docker image sha256:5cb3aa00f89934411ffba5c063a9bc98ace875d8f92e77d0029543d9f2ef4ad0 for alpine:latest ...
Running on runner-78rP5HeK-project-2-concurrent-0 via bf23c668df26...
Reinitialized existing Git repository in /builds/project/app/.git/
HEAD is now at f5a8fe6 gitlab conf
Fetching changes...
fatal: remote origin already exists.
From http://10.34.18.1/project/app
   f5a8fe6..756284c  feature-develop -> origin/feature-develop
Checking out 756284cc as feature-develop...

Skipping Git submodules setup
Checking cache for feature-develop-1...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
$ export JAVA_HOME="/usr/lib/jvm/jre-1.8.0-openjdk"
$ export MAVEN_USER_HOME=`pwd`/.maven
$ chmod +x mvnw
$ ./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v10.13.0 -DnpmVersion=6.4.1 -Dmaven.repo.local=$MAVEN_USER_HOME
Error: JAVA_HOME is not defined correctly.
  We cannot execute /usr/lib/jvm/jre-1.8.0-openjdk/bin/java
ERROR: Job failed: exit code 1

我的.gitlab-ci.yml:

cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
        - .maven/
stages:
    - build
    - test
    - analyze
    - package
    - release
    - deploy


before_script:
    - export JAVA_HOME="/usr/lib/jvm/jre-1.8.0-openjdk"
    - export MAVEN_USER_HOME=`pwd`/.maven
    - chmod +x mvnw
    - ./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v10.13.0 -DnpmVersion=6.4.1 -Dmaven.repo.local=$MAVEN_USER_HOME
    - ./mvnw com.github.eirslett:frontend-maven-plugin:npm -Dmaven.repo.local=$MAVEN_USER_HOME

maven-compile:
    stage: build
    script:
        - ./mvnw compile -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        paths:
            - target/classes/
            - target/generated-sources/
        expire_in: 1 day

maven-test:
    stage: test
    script:
        - ./mvnw test -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        reports:
            junit: target/surefire-reports/TEST-*.xml
        paths:
            - target/test-results
        expire_in: 1 day

frontend-test:
    stage: test
    script:
        - ./mvnw com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.npm.arguments='test -- -u' -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        reports:
            junit: target/test-results/jest/TESTS-*.xml
        paths:
            - target/test-results
        expire_in: 1 day

maven-package:
    stage: package
    script:
        - ./mvnw verify -Pprod -DskipTests -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        paths:
            - target/*.war
        expire_in: 1 day

# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
#docker-push:
#    image: docker:latest
#    services:
#        - docker:dind
#    variables:
#        REGISTRY_URL: registry.gitlab.com
#        DOCKER_HOST: tcp://docker:2375
#        DOCKER_DRIVER: overlay2
#        IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
#    stage: release
#    dependencies:
#        - maven-package
#    before_script:
#        - docker info
#        - cp target/*.war src/main/docker
#    script:
#        - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $REGISTRY_URL
#        - docker build -f src/main/docker/Dockerfile -t $IMAGE_TAG src/main/docker
#        - docker push $IMAGE_TAG

/usr/lib/jvm/jre-1.8.0-openjdk是我的服务器上没有Runner Docker的JAVA_HOME路径

我在我的conf文件中添加了一个docker image image: maven:3-jdk-8

cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
        - .maven/

image: maven:3-jdk-8

stages:
    - build
    - test
    - analyze
    - package
    - release
    - deploy


before_script:
    - chmod +x mvnw
    - export MAVEN_USER_HOME=`pwd`/.maven
    - chmod +x mvnw
    - ./mvnw com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v10.13.0 -DnpmVersion=6.4.1 -Dmaven.repo.local=$MAVEN_USER_HOME
    - ./mvnw com.github.eirslett:frontend-maven-plugin:npm -Dmaven.repo.local=$MAVEN_USER_HOME
[...]

暂无
暂无

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

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