1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-22 06:02:51 +00:00
catalog/maven
Chmouel Boudjnah cfe711305b Pin maven repo test to a revision
Since the "master" branch has been renamed to "main", let's make sure we pin to
a revision and fix if there is other rename going on.

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
2020-06-16 07:50:56 +01:00
..
tests Pin maven repo test to a revision 2020-06-16 07:50:56 +01:00
maven.yaml fixed Maven mirror url param description 2020-05-26 19:32:48 +01:00
README.md Improve Maven Task in v1beta1 2020-04-07 11:33:00 +01:00

Maven

This Task can be used to run a Maven build.

Install the Task

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/v1beta1/maven/maven.yaml

Parameters

  • GOALS: Maven goals to be executed
  • MAVEN_MIRROR_URL: Maven mirror url (to be inserted into ~/.m2/settings.xml)
  • PROXY_USER: Username to login to the proxy server (to be inserted into ~/.m2/settings.xml)
  • PROXY_PASSWORD: Password to login to the proxy server (to be inserted into ~/.m2/settings.xml)
  • PROXY_HOST: Hostname of the proxy server (to be inserted into ~/.m2/settings.xml)
  • PROXY_NON_PROXY_HOSTS: Non proxy hosts to be reached directly bypassing the proxy (to be inserted into ~/.m2/settings.xml)
  • PROXY_PORT: Port number on which the proxy port listens (to be inserted into ~/.m2/settings.xml)
  • PROXY_PROTOCOL: http or https protocol whichever is applicable (to be inserted into ~/.m2/settings.xml)

Workspaces

  • source: PersistentVolumeClaim-type so that volume can be shared among git-clone and maven task
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: maven-source-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi

Usage

This Pipeline and PipelineRun runs a Maven build

With Defaults

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: maven-test-pipeline
spec:
  workspaces:
    - name: shared-workspace
    - name: maven-settings
  tasks:
    - name: fetch-repository
      taskRef:
        name: git-clone
      workspaces:
        - name: output
          workspace: shared-workspace
      params:
        - name: url
          value: https://github.com/spring-projects/spring-petclinic
        - name: subdirectory
          value: ""
        - name: deleteExisting
          value: "true"
    - name: maven-run
      taskRef:
        name: maven
      runAfter:
        - fetch-repository
      workspaces:
        - name: maven-settings
          workspace: maven-settings
        - name: source
          workspace: shared-workspace
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: maven-test-pipeline-run
spec:
  pipelineRef:
    name: maven-test-pipeline
  workspaces:
    - name: maven-settings
      emptyDir: {}
    - name: shared-workspace
      persistentvolumeclaim:
        claimName: maven-source-pvc


With Custom Maven Params

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: maven-test-pipeline
spec:
  workspaces:
    - name: shared-workspace
    - name: maven-settings
  tasks:
    - name: fetch-repository
      taskRef:
        name: git-clone
      workspaces:
        - name: output
          workspace: shared-workspace
      params:
        - name: url
          value: https://github.com/spring-projects/spring-petclinic
        - name: subdirectory
          value: ""
        - name: deleteExisting
          value: "true"
    - name: maven-run
      taskRef:
        name: maven
      params:
        - name: MAVEN_MIRROR_URL
          value: http://repo1.maven.org/maven2
      runAfter:
        - fetch-repository
      workspaces:
        - name: maven-settings
          workspace: maven-settings
        - name: source
          workspace: shared-workspace

PipelineRun same as above in case of default values


With Custom /.m2/settings.yaml

A user provided custom settings.xml can be used with the Maven Task. To do this we need to mount the settings.xml on the Maven Task. Following steps demostrate the use of a ConfigMap to mount a custom settings.xml.

  1. create configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: custom-maven-settings
data:
  settings.xml: |
    <?xml version="1.0" encoding="UTF-8"?>
    <settings>
      <mirrors>
        <mirror>
          <id>maven.org</id>
          <name>Default mirror</name>
          <url>http://repo1.maven.org/maven2</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
      </mirrors>
    </settings>

or

oc create configmap custom-maven-settings --from-file=settings.xml
  1. create TaskRun
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: maven-test-pipeline
spec:
  workspaces:
    - name: shared-workspace
    - name: maven-settings
  tasks:
    - name: fetch-repository
      taskRef:
        name: git-clone
      workspaces:
        - name: output
          workspace: shared-workspace
      params:
        - name: url
          value: https://github.com/spring-projects/spring-petclinic
        - name: subdirectory
          value: ""
        - name: deleteExisting
          value: "true"
    - name: maven-run
      taskRef:
        name: maven
      params:
        - name: MAVEN_MIRROR_URL
          value: http://repo1.maven.org/maven2
      runAfter:
        - fetch-repository
      workspaces:
        - name: maven-settings
          workspace: maven-settings
        - name: source
          workspace: shared-workspace
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: maven-test-pipeline-run
spec:
  pipelineRef:
    name: maven-test-pipeline
  workspaces:
    - name: maven-settings
      configMap:
        name: custom-maven-settings
    - name: shared-workspace
      persistentvolumeclaim:
        claimName: maven-source-pvc