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?
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
name: Build 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
Thanks @Graham Gatus for clarifying this to me. I've took the second option and it works now, Many thanks :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this worked
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.