1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-21 05:55:35 +00:00

Add gradle task version 0.4

This commit is contained in:
Bastiaan Nijkamp 2023-10-25 21:33:11 +02:00 committed by tekton-robot
parent 1ecf61b951
commit 9316f0bdd3
5 changed files with 210 additions and 0 deletions

69
task/gradle/0.4/README.md Normal file
View File

@ -0,0 +1,69 @@
# Gradle
This Task can be used to run a Gradle build on a gradle project.
## Install the Task
```bash
kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/gradle/0.3/raw
```
## Parameters
- **GRADLE_IMAGE**: The base image for gradle (_default_: `gradle:7.6-jdk8`)
- **PROJECT_DIR**: The project directory containing `build.gradle` (_default_: `.`)
- **TASKS**: The gradle tasks to run (_default_: `build`)
## Workspaces
- **source**: `PersistentVolumeClaim`-type so that the volume can be shared among `git-clone` and `gradle` task
```yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gradle-source-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
```
- **gradle-config**: A volume containing the gradle.properties to be used during the gradle run. Is `optional`.
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: gradle-config
data:
gradle.properties: |-
artifactory_contextUrl=https://jfrog.com/artifactory
```
## Platforms
The Task can be run on `linux/amd64`, `linux/s390x` and `linux/ppc64le` platforms.
## Usage
```yaml
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: run-gradle-build
spec:
taskRef:
name: gradle
workspaces:
- name: source
persistentVolumeClaim:
claimName: my-source
- name: gradle-config
configmap:
name: gradle-config
params:
- name: PROJECT_DIR
value: my-workspace
```

View File

@ -0,0 +1,66 @@
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: gradle
labels:
app.kubernetes.io/version: "0.3"
annotations:
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/displayName: Gradle
tekton.dev/categories: Build Tools
tekton.dev/tags: build-tool
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
spec:
description: >-
This Task can be used to run a Gradle build.
workspaces:
- name: source
description: The workspace consisting of the gradle project.
- name: gradle-config
description: The workspace consisting of the custom gradle properties provided by the user.
optional: true
params:
- name: GRADLE_IMAGE
description: Gradle base image.
type: string
default: docker.io/library/gradle:7.6-jdk8@sha256:ebda657f66e04cfa9f152896b4fa70bea4b80561a836adddca3ed85d622f8898
- name: PROJECT_DIR
description: The directory containing build.gradle
type: string
default: "."
- name: TASKS
description: 'The gradle tasks to run (default: build)'
type: array
default:
- build
steps:
- name: gradle-tasks
image: $(params.GRADLE_IMAGE)
env:
- name: GRADLE_USER_HOME
value: "/home/gradle"
workingDir: $(workspaces.source.path)/$(params.PROJECT_DIR)
args:
- "$(params.TASKS)"
script: |
#!/usr/bin/env bash
if [[ "$(workspaces.gradle-config.bound)" == "true" ]]; then
echo "gradle-config workspace is bound"
if [[ -f $(workspaces.gradle-config.path)/gradle.properties ]]; then
echo "copying gradle.properties to /home/gradle"
cp "$(workspaces.gradle-config.path)/gradle.properties" /home/gradle
fi
fi
cmd="gradle $*"
echo "Running gradle task with command below"
echo "$cmd"
eval "$cmd"
volumeMounts:
- mountPath: /home/gradle
name: empty-dir
volumes:
- name: empty-dir
emptyDir: {}

View File

@ -0,0 +1,4 @@
#!/bin/bash
# Add git-clone
add_task git-clone latest

View File

@ -0,0 +1,19 @@
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: gradle-source-pvc
spec:
resources:
requests:
storage: 500Mi
accessModes:
- ReadWriteOnce
---
apiVersion: v1
kind: ConfigMap
metadata:
name: gradle-config
data:
gradle.properties: |-
artifactory_contextUrl=https://jfrog.com/artifactory

View File

@ -0,0 +1,52 @@
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: gradle-test-pipeline
spec:
workspaces:
- name: shared-workspace
- name: gradle-config
tasks:
- name: fetch-code
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-workspace
params:
- name: url
value: https://github.com/crshnburn/simple-gradle
- name: subdirectory
value: ""
- name: deleteExisting
value: "true"
- name: gradle-run
taskRef:
name: gradle
runAfter:
- fetch-code
params:
- name: TASKS
value:
- build
workspaces:
- name: source
workspace: shared-workspace
- name: gradle-config
workspace: gradle-config
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: gradle-test-pipeline-rune
spec:
pipelineRef:
name: gradle-test-pipeline
workspaces:
- name: shared-workspace
persistentvolumeclaim:
claimName: gradle-source-pvc
- name: gradle-config
configmap:
name: gradle-config