Search code examples
javagradlebitbucketgradlewbitbucket-pipelines

Bitbucket pipelines could not find Gradle


I created a project with Java 11 and Gradle 6.2. I configured Bitbucket pipelines and pushed changes, but Bitbucket could not find Gradle to run its commands. I used this pipeline configuration yml:

image: openjdk:11

pipelines:
  default: #this runs for any unspecified branches
    - step:
        name: Install dependencies
        caches:
          - gradle
        script:
          - echo 'Put any bash command here'
          - java -version
    - step:
        name: Run tests
        script:
          - bash ./gradlew test
    - step:
        name: Build artifacts
        script:
          - bash ./gradlew clean build
        artifacts:
          - build/**

  pull-requests:
    '**': #this runs as default for any branch not elsewhere defined
      - step:
          name: Install dependencies
          caches:
            - gradle
          script:
            - echo 'Put any bash command here'
            - java -version
      - step:
          name: Run tests
          script:
            - bash ./gradlew test
      - step:
          name: Build artifacts
          script:
            - bash ./gradlew clean build
          artifacts:
            - build/**

  branches:
    master: #this runs only 'master' branch
      - step:
          name: Install dependencies
          caches:
            - gradle
          script:
            - echo 'Put any bash command here'
            - java -version
      - step:
          name: Run tests
          script:
            - bash ./gradlew test
      - step:
          name: Build artifacts
          script:
            - bash ./gradlew clean build
          artifacts:
            - build/**

      - step:
          name: Deploy artifacts to the server
          deployment: production
          script:
            - pipe: atlassian/scp-deploy:0.3.3
              variables:
                USER: $SERVER_USER
                SERVER: $SERVER_IP
                VERSION: $BUILD_VERSION
                REMOTE_PATH: '/var/autotrack'
                LOCAL_PATH: 'build/libs/autotrack-$VERSION.jar' 


But I got the following error:

bash ./gradlew test
bash: ./gradlew: No such file or directory

Bitbucket Pipelines - CI build error

How can I solve this?


Solution

  • openjdk:11 image does not contain Gradle. That's why we need to use another image that contains Java and Gradle in one place. For example, this gradle:6.3.0-jdk11 image can be used.

    image: gradle:6.3.0-jdk11
    
    pipelines:
      default:
        - step:
            name: Test and Build
            script:
              - gradle clean build