Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JAVA_HOME is not set and no 'java' command could be found in your PATH. bitbucket pipeline

Mahmoud August 30, 2018

Hi i tried to exxecute a gradle command in bitbucket pipeline

definitions:
services:
java:
image: openjdk:8
pipelines:
default:
- step:
name: Build And Test
services:
- java
script:
- bash ./gradlew clean build
- bash ./gradlew test
- step:
name: configure gcloud
deployment: test
image: google/cloud-sdk:214.0.0-alpine
services:
- java
- docker
caches:
- gradle
script:
- gcloud auth configure-docker --quiet
- docker login -u _json_key -p "$GCR_JSON_KEY" https://gcr.io
- bash ./gradlew bake -Penv=test -PisRelease=false --info --stacktrace

 

 

when it tried to execute the latest task 

          - bash ./gradlew bake -Penv=test -PisRelease=false --info --stacktrace

 it give the error 

 JAVA_HOME is not set and no 'java' command could be found in your PATH. 

 

what is the issue in this case? 

1 answer

1 accepted

2 votes
Answer accepted
Graham Gatus
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 30, 2018

Hi @Mahmoud

I can see you've attempted to add the 'openjdk:8' docker image as a service. Services are designed to provide additional databases, webservices etc as part of your build, and not provide CLI tools (the exception is the pipelines built in 'docker' service, which in addition to providing a docker daemon, also makes the docker CLI available by mounting in a volume containing the docker CLI  - see https://confluence.atlassian.com/bitbucket/run-docker-commands-in-bitbucket-pipelines-879254331.html). 

The pipelines default image already provides Java 1.8.0_151, so if you want to continue using this, you can re-write your first step to be:

    - step:
name: Build And Test
script:
- bash ./gradlew clean build
- bash ./gradlew test

In your second step, you will need to either:

- Use a custom docker image that has both gcloud tools and the jdk, or

- Use the default pipelines image, and install the gcloud CLI manually

The following is an example step which has docker as a service, jdk and gcloud CLI, where the google cloud CLI is installed as part of the build:

step: 
services: 
docker 
nameBuild And Test 
script: 
# Install gcloud CLI 
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" 
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list 
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - 
sudo apt-get update && sudo apt-get install -y google-cloud-sdk 
gcloud --version 
java -version 
docker --version

Instructions for installing the gcloud CLI can be found at https://cloud.google.com/sdk/docs/downloads-apt-get

Cheers

Graham

Mahmoud September 2, 2018

Thanks @Graham Gatus for clarifying this to me. I've took the second option and it works now, Many thanks :) 

Like Mohd Farid Mansoori likes this
Jerry Buaba
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 30, 2019

this worked

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events