Bitbucket管道找不到Gradle

时间:2020-04-10 08:10:00

标签: java gradle bitbucket gradlew bitbucket-pipelines

我用Java 11和Gradle 6.2创建了一个项目。我配置了Bitbucket管道并推送了更改,但是Bitbucket找不到Gradle运行其命令。 我使用了以下管道配置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' 


但是我遇到了以下错误:

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

Bitbucket Pipelines - CI build error

我该如何解决?

2 个答案:

答案 0 :(得分:2)

openjdk:11图片不包含Gradle。这就是为什么我们需要在一个地方使用另一幅包含Java和Gradle的图像。例如,可以使用此gradle:6.3.0-jdk11图像。

image: gradle:6.3.0-jdk11

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

答案 1 :(得分:0)

请问您是否可以通过此修改步骤来运行构建?

- step:
    name: Run tests
    script:
      - bash ls -lart
      - bash ./gradlew test

我希望这可以澄清问题。