tekton TriggerTemplate资源

tekton新课发布:https://edu.csdn.net/course/detail/35202

什么是TriggerTemplate

创建资源的模板,比如用来创建 PipelineResource 和 PipelineRun

支持的资源

v1alpha1 v1beta1
pipelines pipelines
pipelineruns pipelineruns
tasks tasks
taskruns taskruns
clustertasks clustertasks
conditions
pipelineresources

资源详解

resourcetemplates

tasks

triggerTemplate/task-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: Task
    metadata:
      name: params-string 
    spec: 
      params:
      - name: directory
        type: string
        description: The directory containing the build context.
        default: /workspace
      steps:
      - image: ubuntu
        command: [pwd]
        workingDir: "$(params.directory)"
        imagePullPolicy: IfNotPresent

taskruns

triggerTemplate/taskruns-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  params:
  - name: array-param
    description: test
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: Task
    metadata:
      name: my-params-array
    spec:
      params:
      - name: array-param
        type: array
        default:
        - a
        - b
        - c
      steps:
      - image: ubuntu
        command: [echo]
        args:
        - "$(params.array-param[*])"
        imagePullPolicy: IfNotPresent
  - apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:
      generateName: params-
    spec:
      taskRef:
        name: my-params-array
      params:
      - name: array-param
        value: $(tt.params.array-param)

clustertasks

triggerTemplate/clustertasks-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  params:
  - name: array-param
    description: test
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: ClusterTask
    metadata:
      name: my-params-array
    spec:
      params:
      - name: array-param
        type: array
        default:
        - a
        - b
        - c
      steps:
      - image: ubuntu
        command: [echo]
        args:
        - "$(params.array-param[*])"
        imagePullPolicy: IfNotPresent
  - apiVersion: tekton.dev/v1beta1
    kind: TaskRun
    metadata:
      generateName: params-
    spec:
      taskRef:
        name: my-params-array
        kind: ClusterTask
      params:
      - name: array-param
        value: $(tt.params.array-param)

pipelineresources

triggerTemplate/pipelineresources-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  params:
  - name: url
  - name: revision
  resourcetemplates:
  - apiVersion: tekton.dev/v1alpha1
    kind: PipelineResource
    metadata:
      name: workspace
    spec:
      type: git
      params:
      - name: url
        value: $(tt.params.url)
      - name: revision
        value: $(tt.params.revision)

pipelines

triggerTemplate/pipelines-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: Pipeline
    metadata:
      name: mypipeline
    spec:
      tasks:
      - name: build-app
        taskRef:
          name: build-push-kaniko
        resources:
          inputs:
          - name: workspace
            resource: workspace
          outputs:
          - name: builtImage
            resource: my-image
      - name: deploy-app
        taskRef:
          name: kubectl-deploy
        resources:
          inputs:
          - name: workspace
            resource: workspace
          - name: image
            resource: my-image
            from:
              - build-app
        params:
        - name: script_body
          value: $(params.script_body_pipeline)
      params:
      - name: script_body_pipeline
        type: string
      resources:
        - name: workspace
          type: git
        - name: my-image
          type: image

pipelineruns

triggerTemplate/pipelineruns-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: PipelineRun
    metadata:
      generateName: mypipeline-run
    spec:
      serviceAccountName: test-task-robot-git-ssh
      pipelineRef:
        name: mypipeline
      params:
      - name: script_body_pipeline
        value: "kubectl apply -f /workspace/workspace/deployment.yaml "
      resources:
        - name: workspace
          resourceRef: 
            name: workspace
        - name: my-image
          resourceRef: 
            name: my-image

conditions

triggerTemplate/conditions-template.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: template
spec:
  resourcetemplates:
  - apiVersion: tekton.dev/v1alpha1
    kind: Condition
    metadata:
      name: is-equal
    spec:
      params:
      - name: left
        type: string
      - name: right
        type: string
      check:
        image: alpine
        script: |
          #!/bin/sh
          if [ $(params.left) = $(params.right) ]; then
            echo "$(params.left) == $(params.right)"
            exit 0
          else
            echo "$(params.left) != $(params.right)"
            exit 1
          fi
上一篇:k8s基于NFS创建动态存储StorageClass


下一篇:redis (error) WRONGTYPE Operation against a key holding the wrong kind of value