diff --git a/src/rules.ts b/src/rules.ts index 2b3f9fe..a98f11f 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -14,7 +14,9 @@ const createReporter = (rule, config, reporter) => { const parse = (docs): Tekton => { const tkn: Tekton = { tasks: Object.fromEntries( - docs.filter((item) => item.kind === 'Task').map((item) => [item.metadata.name, item]), + docs + .filter((item) => item.kind === 'Task' || item.kind === 'ClusterTask') + .map((item) => [item.metadata.name, item]), ), pipelines: Object.fromEntries( docs.filter((item) => item.kind === 'Pipeline').map((item) => [item.metadata.name, item]), diff --git a/src/rules/no-missing-resource.ts b/src/rules/no-missing-resource.ts index f4d7654..9bb2a31 100644 --- a/src/rules/no-missing-resource.ts +++ b/src/rules/no-missing-resource.ts @@ -71,11 +71,20 @@ export default (docs, tekton, report) => { const name = task.taskRef.name; if (!tekton.tasks[name]) { - report( - `Pipeline '${pipeline.metadata.name}' references task '${name}' but the referenced task cannot be found. To fix this, include all the task definitions to the lint task for this pipeline.`, - task.taskRef, - 'name', - ); + if (task.taskRef.kind && task.taskRef.kind === 'ClusterTask') { + report( + `Pipeline '${pipeline.metadata.name}' references cluster task '${name}' but the referenced task cannot be found locally.`, + task.taskRef, + 'name', + ); + } else { + report( + `Pipeline '${pipeline.metadata.name}' references task '${name}' but the referenced task cannot be found. To fix this, include all the task definitions to the lint task for this pipeline.`, + task.taskRef, + 'name', + ); + } + continue; } } @@ -94,11 +103,19 @@ export default (docs, tekton, report) => { const name = task.taskRef.name; if (!tekton.tasks[name]) { - report( - `Pipeline '${pipeline.metadata.name}' references task '${name}' but the referenced task cannot be found. To fix this, include all the task definitions to the lint task for this pipeline.`, - task.taskRef, - 'name', - ); + if (task.taskRef.kind && task.taskRef.kind === 'ClusterTask') { + report( + `Pipeline '${pipeline.metadata.name}' references cluster task '${name}' but the referenced task cannot be found locally.`, + task.taskRef, + 'name', + ); + } else { + report( + `Pipeline '${pipeline.metadata.name}' references task '${name}' but the referenced task cannot be found. To fix this, include all the task definitions to the lint task for this pipeline.`, + task.taskRef, + 'name', + ); + } continue; } } diff --git a/system-tests/field/clustertasks/cluster-task.yaml b/system-tests/field/clustertasks/cluster-task.yaml new file mode 100644 index 0000000..fb00569 --- /dev/null +++ b/system-tests/field/clustertasks/cluster-task.yaml @@ -0,0 +1,19 @@ +apiVersion: tekton.dev/v1beta1 +kind: ClusterTask +metadata: + name: generate-random-number +spec: + description: Generates a random number. + inputs: + parameters: + - name: min + type: string + - name: max + type: string + steps: + - name: generate-random-number + image: busybox + command: ["/bin/echo", "$((RANDOM % $(params.max - params.min) + params.min))"] + outputs: + result: + type: string \ No newline at end of file diff --git a/system-tests/field/clustertasks/pipeline.yaml b/system-tests/field/clustertasks/pipeline.yaml new file mode 100644 index 0000000..7923c5a --- /dev/null +++ b/system-tests/field/clustertasks/pipeline.yaml @@ -0,0 +1,13 @@ +apiVersion: tekton.dev/v1beta1 +kind: Pipeline +metadata: + name: generate-random-number-pipeline +spec: + tasks: + - name: generate-random-number + taskRef: + name: generate-random-number + kind: ClusterTask + results: + - name: random-number + value: $(tasks.generate-random-number.outputs.result) \ No newline at end of file