1
0
mirror of https://github.com/tektoncd/catalog.git synced 2025-01-17 12:26:54 +00:00

Fix #1309 : Add some commonly used maven builds metadata as results to maven task

This commit is contained in:
Andrea Tarocchi 2024-12-06 12:53:38 +01:00 committed by tekton-robot
parent 456b01c6f6
commit af4fc41820
3 changed files with 62 additions and 17 deletions

View File

@ -5,7 +5,7 @@ This Task can be used to run a Maven goals on a simple maven project or on a mul
## Install the Task
```bash
kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/maven/0.3/raw
kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/maven/0.4/raw
```
## Parameters
@ -23,6 +23,12 @@ kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/maven/0.3/ra
- **PROXY_PROTOCOL**: http or https protocol whichever is applicable (to be inserted into ~/.m2/settings.xml)
- **CONTEXT_DIR**: The context directory within the repository for sources on which we want to execute maven goals. (_Default_: ".")
## Results
* **group-id**: The Maven project group id
* **artifact-id**: The Maven project artifact id
* **version**: The Maven project version
## Workspaces
- **source**: `PersistentVolumeClaim`-type so that volume can be shared among `git-clone` and `maven` task
@ -67,7 +73,7 @@ This Pipeline and PipelineRun runs a Maven build on a particular module in a mul
### With Defaults
```yaml
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: maven-test-pipeline
@ -111,7 +117,7 @@ spec:
- name: maven-local-repo
workspace: maven-local-m2
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: maven-test-pipeline-run
@ -134,7 +140,7 @@ spec:
### With Custom Maven Params
```yaml
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: maven-test-pipeline
@ -222,7 +228,7 @@ oc create configmap custom-maven-settings --from-file=settings.xml
2. create `Pipeline` and `PipelineRun`
```yaml
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: maven-test-pipeline
@ -267,7 +273,7 @@ spec:
workspace: maven-local-m2
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: maven-test-pipeline-run

View File

@ -1,11 +1,11 @@
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: maven
labels:
app.kubernetes.io/version: "0.3"
app.kubernetes.io/version: "0.4"
annotations:
tekton.dev/pipelines.minVersion: "0.17.0"
tekton.dev/pipelines.minVersion: "0.50.0"
tekton.dev/categories: Build Tools
tekton.dev/tags: build-tool
tekton.dev/platforms: "linux/amd64,linux/s390x,linux/ppc64le"
@ -75,6 +75,16 @@ spec:
The context directory within the repository for sources on
which we want to execute maven goals.
default: "."
results:
- description: Maven project group id
name: group-id
type: string
- description: Maven project artifact id
name: artifact-id
type: string
- description: version
name: version
type: string
steps:
- name: mvn-settings
image: registry.access.redhat.com/ubi8/ubi-minimal:8.2
@ -146,9 +156,15 @@ spec:
- name: mvn-goals
image: $(params.MAVEN_IMAGE)
workingDir: $(workspaces.source.path)/$(params.CONTEXT_DIR)
command: ["/usr/bin/mvn"]
args:
- -s
- $(workspaces.maven-settings.path)/settings.xml
- "$(params.GOALS)"
- '-Dmaven.repo.local=$(workspaces.maven-local-repo.path)/.m2'
args: ["$(params.GOALS[*])"]
script: |
#!/usr/bin/env bash
/usr/bin/mvn -s $(workspaces.maven-settings.path)/settings.xml "$@" '-Dmaven.repo.local=$(workspaces.maven-local-repo.path)/.m2'
GROUPID=$(/usr/bin/mvn -s $(workspaces.maven-settings.path)/settings.xml '-Dmaven.repo.local=$(workspaces.maven-local-repo.path)/.m2' -q -Dexec.executable=echo -Dexec.args='${project.gruopId}' --non-recursive exec:exec)
echo -n $GROUPID | tee $(results.group-id.path)
ARTIFACTID=$(/usr/bin/mvn -s $(workspaces.maven-settings.path)/settings.xml '-Dmaven.repo.local=$(workspaces.maven-local-repo.path)/.m2' -q -Dexec.executable=echo -Dexec.args='${project.artifactId}' --non-recursive exec:exec)
echo -n $ARTIFACTID | tee $(results.artifact-id.path)
VERSION=$(/usr/bin/mvn -s $(workspaces.maven-settings.path)/settings.xml '-Dmaven.repo.local=$(workspaces.maven-local-repo.path)/.m2' -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)
echo -n $VERSION | tee $(results.version.path)

View File

@ -1,5 +1,20 @@
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: test-mvn-results
spec:
params:
- name: input
type: string
steps:
- name: verify
image: registry.access.redhat.com/ubi8/ubi-minimal:8.2
script: |
#!/bin/bash
echo "$(params.input)"
---
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: maven-test-pipeline
@ -62,8 +77,16 @@ spec:
workspace: shared-workspace
- name: maven-local-repo
workspace: maven-local-m2
- name: verify-mvn-results
taskRef:
name: test-mvn-results
runAfter:
- maven-run-build-2
params:
- name: input
value: $(tasks.maven-run-build-2.group-id) $(tasks.maven-run-build-2.artifact-id) $(tasks.maven-run-build-2.version)
---
apiVersion: tekton.dev/v1beta1
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: maven-test-pipeline-run