Drone pipeline JAVA_HOME is not defined correctly

Hi all
I have created my first CI pipeline with DroneCI as follows:

---
kind: pipeline
type: exec
name: Keycloak extensions deployment

steps:
- name: Build JAR files
  commands:
    - ./mvnw clean
    - ./mvnw install

- name: Run docker-compose
  volumes:
    - name: docker_sock
      path: /var/run/docker.sock
  commands:
    - docker-compose up

volumes:
  - name: docker_sock
    host:
      path: /var/run/docker.sock

trigger:
  branch:
    - master 

I’ve got error message on the first step:

+ ./mvnw clean
Error: JAVA_HOME is not defined correctly.
  We cannot execute 

and I would say, Java is installed properly:

echo $JAVA_HOME
/home/admin/.sdkman/candidates/java/current  

java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.18.0, JRE 11 Linux amd64-64-Bit Compressed References 20200116_433 (JIT enabled, AOT enabled)
OpenJ9   - 6968c18d7
OMR      - 7a1b0239a
JCL      - 104cab2452 based on jdk-11.0.6+10)

I’ve installed JDK via SDKman.

When I manually clone the repo and run the statement

./mvnw clean
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Dataxu custom theme                                                [jar]
[INFO] SPI registration profile                                           [jar]
[INFO] keycloak-extensions                                                [pom] 

then it works.

What am I doing wrong?

Thanks

@softshipper each exec pipelines ha its own temporary home directory, therefore, it will not read your HOME directory or your bash profile. You can instead set global environment variables (such as JAVA_HOME) in your yaml [1] or you can set this value globally [2][3].

[1] https://docs.drone.io/pipeline/environment/syntax/
[2] https://docs.drone.io/runner/exec/configuration/reference/drone-runner-environ/ or
[3] https://docs.drone.io/runner/exec/configuration/reference/drone-runner-envfile/

1 Like

@ashwilliams1 Thanks so much, I will try do as you say.