Bitbucket Pipelines 无法找到 Gradle。

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

Bitbucket pipelines could not find Gradle

问题

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

  1. image: openjdk:11
  2. pipelines:
  3. default: #this runs for any unspecified branches
  4. - step:
  5. name: 安装依赖
  6. caches:
  7. - gradle
  8. script:
  9. - echo '在此处放置任何bash命令'
  10. - java -version
  11. - step:
  12. name: 运行测试
  13. script:
  14. - bash ./gradlew test
  15. - step:
  16. name: 构建构件
  17. script:
  18. - bash ./gradlew clean build
  19. artifacts:
  20. - build/**
  21. pull-requests:
  22. '**': #this runs as default for any branch not elsewhere defined
  23. - step:
  24. name: 安装依赖
  25. caches:
  26. - gradle
  27. script:
  28. - echo '在此处放置任何bash命令'
  29. - java -version
  30. - step:
  31. name: 运行测试
  32. script:
  33. - bash ./gradlew test
  34. - step:
  35. name: 构建构件
  36. script:
  37. - bash ./gradlew clean build
  38. artifacts:
  39. - build/**
  40. branches:
  41. master: #this runs only 'master' branch
  42. - step:
  43. name: 安装依赖
  44. caches:
  45. - gradle
  46. script:
  47. - echo '在此处放置任何bash命令'
  48. - java -version
  49. - step:
  50. name: 运行测试
  51. script:
  52. - bash ./gradlew test
  53. - step:
  54. name: 构建构件
  55. script:
  56. - bash ./gradlew clean build
  57. artifacts:
  58. - build/**
  59. - step:
  60. name: 将构件部署到服务器
  61. deployment: production
  62. script:
  63. - pipe: atlassian/scp-deploy:0.3.3
  64. variables:
  65. USER: $SERVER_USER
  66. SERVER: $SERVER_IP
  67. VERSION: $BUILD_VERSION
  68. REMOTE_PATH: '/var/autotrack'
  69. 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:

  1. image: openjdk:11
  2. pipelines:
  3. default: #this runs for any unspecified branches
  4. - step:
  5. name: Install dependencies
  6. caches:
  7. - gradle
  8. script:
  9. - echo 'Put any bash command here'
  10. - java -version
  11. - step:
  12. name: Run tests
  13. script:
  14. - bash ./gradlew test
  15. - step:
  16. name: Build artifacts
  17. script:
  18. - bash ./gradlew clean build
  19. artifacts:
  20. - build/**
  21. pull-requests:
  22. '**': #this runs as default for any branch not elsewhere defined
  23. - step:
  24. name: Install dependencies
  25. caches:
  26. - gradle
  27. script:
  28. - echo 'Put any bash command here'
  29. - java -version
  30. - step:
  31. name: Run tests
  32. script:
  33. - bash ./gradlew test
  34. - step:
  35. name: Build artifacts
  36. script:
  37. - bash ./gradlew clean build
  38. artifacts:
  39. - build/**
  40. branches:
  41. master: #this runs only 'master' branch
  42. - step:
  43. name: Install dependencies
  44. caches:
  45. - gradle
  46. script:
  47. - echo 'Put any bash command here'
  48. - java -version
  49. - step:
  50. name: Run tests
  51. script:
  52. - bash ./gradlew test
  53. - step:
  54. name: Build artifacts
  55. script:
  56. - bash ./gradlew clean build
  57. artifacts:
  58. - build/**
  59. - step:
  60. name: Deploy artifacts to the server
  61. deployment: production
  62. script:
  63. - pipe: atlassian/scp-deploy:0.3.3
  64. variables:
  65. USER: $SERVER_USER
  66. SERVER: $SERVER_IP
  67. VERSION: $BUILD_VERSION
  68. REMOTE_PATH: '/var/autotrack'
  69. 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 镜像。

  1. image: gradle:6.3.0-jdk11
  2. pipelines:
  3. default:
  4. - step:
  5. name: 测试和构建
  6. script:
  7. - 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.

  1. image: gradle:6.3.0-jdk11
  2. pipelines:
  3. default:
  4. - step:
  5. name: Test and Build
  6. script:
  7. - gradle clean build
  8. </details>
  9. # 答案2
  10. **得分**: 0
  11. 能否使用这个修改后的步骤运行构建,请?
  12. - 步骤:
  13. 名称:运行测试
  14. 脚本:
  15. - bash ls -lart
  16. - bash ./gradlew test
  17. 我希望这能澄清问题。
  18. <details>
  19. <summary>英文:</summary>
  20. Are you able to run the build with this modified step, please?
  21. - step:
  22. name: Run tests
  23. script:
  24. - bash ls -lart
  25. - bash ./gradlew test
  26. I hope that this will clarify the issue.
  27. </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:

确定