首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tekton CI/CD中的Gradle构建失败

Tekton CI/CD中的Gradle构建失败
EN

Stack Overflow用户
提问于 2022-06-19 00:25:19
回答 1查看 240关注 0票数 0

下面是用于Gradle构建的管道任务,该任务从bitbucket回购中克隆项目,并尝试构建应用程序。

代码语言:javascript
复制
  tasks:
    - name: clone-repository
      taskRef:
        name: git-clone
      workspaces:
        - name: output
          workspace: shared-workspace
      params:
        - name: url
          value: "$(params.repo-url)"
        - name: deleteExisting
          value: "true"
    - name: build
      taskRef:
        name: gradle
      runAfter:
        - "clone-repository"
      params:
        - name: TASKS
          value: build -x test
        - name: GRADLE_IMAGE
          value: docker.io/library/gradle:jdk17-alpine@sha256:dd16ae381eed88d2b33f977b504fb37456e553a1b9c62100b8811e4d8dec99ff
      workspaces:
        - name: source
          workspace: shared-workspace

我有下面的项目结构

settings.gradle包含以下项目

代码语言:javascript
复制
rootProject.name = 'discount'
include 'core'
include 'infrastructure'
include 'shared'
include 'discount-api'

使用以下代码运行管道时

代码语言:javascript
复制
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: run-pipeline
  namespace: tekton-pipelines
spec:
  serviceAccountName: git-service-account
  pipelineRef:
    name: git-clone-pipeline
  workspaces:
    - name: shared-workspace
      persistentVolumeClaim:
        claimName: fetebird-discount-pvc
  params:
    - name: repo-url
      value: git@bitbucket.org:anandjaisy/discount.git

获得异常,如

代码语言:javascript
复制
FAILURE: Build failed with an exception.

* What went wrong:
Task 'build -x test' not found in root project 'discount'.

我使用了Tekton目录https://github.com/tektoncd/catalog/blob/main/task/gradle/0.1/gradle.yaml中的任务

如果我将PROJECT_DIR值作为./discount-api传递给Gradle任务。我得到了一个异常,因为settings.gradle没有找到。这是正确的,因为该项目没有setting.gradle文件。

主要项目是discount-api。我需要构建应用程序。不知道是怎么回事。在本地env上,如果我在根目录中执行./gradlew build,则应用程序将成功构建。

EN

回答 1

Stack Overflow用户

发布于 2022-06-19 09:37:42

错误消息告诉我们关于Task 'build -x test' not found in root project 'discount'

在tekton目录中检查该任务,我们可以看到:

代码语言:javascript
复制
....
- name: TASKS
  description: 'The gradle tasks to run (default: build)'
  type: string
  default: build
steps:
- name: gradle-tasks
  image: $(params.GRADLE_IMAGE)
  workingDir: $(workspaces.source.path)/$(params.PROJECT_DIR)
  command:
    - gradle
  args:
    - $(params.TASKS)

现在,在您的管道中,将TASKS参数设置为build -x test。这是你的问题。

正如您在上面所看到的,这个TASKS参数是一个字符串。而你想要使用数组。

您应该能够更改param定义,例如:

代码语言:javascript
复制
....
- name: TASKS
  description: 'The gradle tasks to run (default: build)'
  type: array
  default:
  - build
steps:
- name: gradle-tasks
  image: $(params.GRADLE_IMAGE)
  workingDir: $(workspaces.source.path)/$(params.PROJECT_DIR)
  command:
    - gradle
  args: [ "$(params.TASKS)" ]

这将确保将"build“、"-x”和"test“作为单独的字符串发送到gradle。虽然当前的尝试等同于运行gradle "build -x test",但会导致错误。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72673567

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档