下面是用于Gradle构建的管道任务,该任务从bitbucket回购中克隆项目,并尝试构建应用程序。
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包含以下项目
rootProject.name = 'discount'
include 'core'
include 'infrastructure'
include 'shared'
include 'discount-api'使用以下代码运行管道时
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获得异常,如
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,则应用程序将成功构建。
发布于 2022-06-19 09:37:42
错误消息告诉我们关于Task 'build -x test' not found in root project 'discount'
在tekton目录中检查该任务,我们可以看到:
....
- 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定义,例如:
....
- 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",但会导致错误。
https://stackoverflow.com/questions/72673567
复制相似问题