Bitbucket Pipelines 无法找到 Gradle。

huangapple go评论95阅读模式
英文:

Bitbucket pipelines could not find Gradle

问题

我使用Java 11和Gradle 6.2创建了一个项目。我配置了Bitbucket Pipelines并推送了更改,但Bitbucket无法找到Gradle来运行其命令。
我使用了以下流水线配置yml:

image: openjdk:11

pipelines:
  default: #this runs for any unspecified branches
    - step:
        name: 安装依赖
        caches:
          - gradle
        script:
          - echo '在此处放置任何bash命令'
          - java -version
    - step:
        name: 运行测试
        script:
          - bash ./gradlew test
    - step:
        name: 构建构件
        script:
          - bash ./gradlew clean build
        artifacts:
          - build/**

  pull-requests:
    '**': #this runs as default for any branch not elsewhere defined
      - step:
          name: 安装依赖
          caches:
            - gradle
          script:
            - echo '在此处放置任何bash命令'
            - java -version
      - step:
          name: 运行测试
          script:
            - bash ./gradlew test
      - step:
          name: 构建构件
          script:
            - bash ./gradlew clean build
          artifacts:
            - build/**

  branches:
    master: #this runs only 'master' branch
      - step:
          name: 安装依赖
          caches:
            - gradle
          script:
            - echo '在此处放置任何bash命令'
            - java -version
      - step:
          name: 运行测试
          script:
            - bash ./gradlew test
      - step:
          name: 构建构件
          script:
            - bash ./gradlew clean build
          artifacts:
            - build/**

      - step:
          name: 将构件部署到服务器
          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: 没有那个文件或目录

Bitbucket Pipelines 无法找到 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 无法找到 Gradle。

How can I solve this?

答案1

得分: 3

openjdk:11 镜像不包含 Gradle。这就是为什么我们需要使用另一个同时包含 Java 和 Gradle 的镜像。例如,可以使用 gradle:6.3.0-jdk11 镜像。

image: gradle:6.3.0-jdk11

pipelines:
  default:
    - step:
        name: 测试和构建
        script:
          - gradle clean build
英文:

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

</details>



# 答案2
**得分**: 0

能否使用这个修改后的步骤运行构建,请?

    - 步骤:
        名称:运行测试
        脚本:
          - bash ls -lart
          - bash ./gradlew test

我希望这能澄清问题。

<details>
<summary>英文:</summary>

Are you able to run the build with this modified step, please?


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


I hope that this will clarify the issue.


</details>



huangapple
  • 本文由 发表于 2020年4月10日 16:10:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/61136340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定