欢迎关注我的公众号:
目前刚开始写一个月,一共写了18篇原创文章,文章目录如下:
istio防故障利器,你知道几个,istio新手不要读,太难!
不懂envoyfilter也敢说精通istio系列-http-rbac-不要只会用AuthorizationPolicy配置权限
不懂envoyfilter也敢说精通istio系列-02-http-corsFilter-不要只会vs
不懂envoyfilter也敢说精通istio系列-03-http-csrf filter-再也不用再代码里写csrf逻辑了
不懂envoyfilter也敢说精通istio系列http-jwt_authn-不要只会RequestAuthorization
不懂envoyfilter也敢说精通istio系列-05-fault-filter-故障注入不止是vs
不懂envoyfilter也敢说精通istio系列-06-http-match-配置路由不只是vs
不懂envoyfilter也敢说精通istio系列-07-负载均衡配置不止是dr
不懂envoyfilter也敢说精通istio系列-08-连接池和断路器
不懂envoyfilter也敢说精通istio系列-09-http-route filter
不懂envoyfilter也敢说精通istio系列-network filter-redis proxy
不懂envoyfilter也敢说精通istio系列-network filter-HttpConnectionManager
不懂envoyfilter也敢说精通istio系列-ratelimit-istio ratelimit完全手册
tekton新课发布:ci/cd之tekton实战--其他视频教程-系统/网络/运维-CSDN程序员研修院
什么是pipeline
用于定义一系列完成特定构建或交付目标的任务。pipeline的运行是由事件触发或从PipelineRun调用。pipeline和task的区别在于,task只能执行一个task,而pipeline中可以编排多个task,注意是编排,并不只是简单运行。pipeline的spec.tasks定义了需要编排的task,是个数组,而这个数组中的task的顺序并不一定是执行顺序,pipeline中task的执行顺序是可以指定的。
资源详解
tasks
name
taskRef
pipeline/task-hello.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello
spec:
steps:
- name: hello
image: ubuntu
command:
- echo
args:
- "Hello World!"
pipeline/pipeline-name-taskRef.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: name
spec:
tasks:
- name: hello
taskRef:
name: hello
taskSpec
pipeline/pipeline-taskSpec.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: taskspec
spec:
tasks:
- name: hello
taskSpec:
steps:
- name: hello
image: ubuntu
command:
- echo
args:
- "Hello World!"
from
pipeline/from/sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: test-task-robot-git-ssh
secrets:
- name: registry-secret
kubectl create secret docker-registry registry-secret \
--docker-server=registry.cn-beijing.aliyuncs.com \
--docker-username=195446040@qq.com \
--docker-password=123456 -n tekton
kubectl create clusterrolebinding cluster-admin-test-task --clusterrole=cluster-admin --serviceaccount=tekton:test-task-robot-git-ssh -n tekton
pipeline/from/res-image.yaml
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: my-image
spec:
type: image
params:
- name: url
value: registry.cn-beijing.aliyuncs.com/hxpdocker/testimage
pipeline/from/res-git.yaml
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: workspace
spec:
type: git
params:
- name: url
value: https://codechina.csdn.net/hxpjava1/test.git
- name: revision
value: master
pipeline/from/task-build-push-kaniko.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-push-kaniko
spec:
resources:
inputs:
- name: workspace
type: git
outputs:
- name: builtImage
type: image
params:
- name: pathToDockerFile
description: The path to the dockerfile to build
default: /workspace/workspace/Dockerfile
- name: pathToContext
description: The build context used by Kaniko
default: /workspace/workspace
steps:
- name: build-and-push
image: registry.us-west-1.aliyuncs.com/hxpapp/kaniko-executor:latest
#env:
#- name: "DOCKER_CONFIG"
# value: "/tekton/home/.docker/"
args:
- --dockerfile=$(inputs.params.pathToDockerFile)
- --destination=$(outputs.resources.builtImage.url)
- --context=$(inputs.params.pathToContext)
- --oci-layout-path=$(inputs.resources.builtImage.path)
securityContext:
runAsUser: 0
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker/
volumes:
- name: kaniko-secret
secret:
secretName: registry-secret
items:
- key: .dockerconfigjson
path: config.json
pipeline/from/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
params:
- name: script_body
type: string
#default: "kubectl apply -f deployment.yaml -n tekton"
resources:
inputs:
- name: image
type: image
- name: workspace
type: git
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/from/pipeline-my.yaml
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
pipeline/from/pipelinerun-my.yaml
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
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
labels:
app: my-app
spec:
selector:
matchLabels:
app: my-app
replicas: 1
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: registry.cn-beijing.aliyuncs.com/hxpdocker/testimage
runAfter
pipeline/pipeline-runAfter.yaml
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
runAfter:
- build-app
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
retries
pipeline/pipeline-retries.yaml
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
runAfter:
- build-app
retries: 2
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
pipeline/pipelinerun-retries.yaml
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/deploymen2.yaml "
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
conditions
pipeline/condition/condition-is-equal.yaml
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
pipeline/condition/pipeline-my.yaml
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
conditions:
- conditionRef: is-equal
params:
- name: left
value: $(params.left_pipeline)
- name: right
value: $(params.right_pipeline)
taskRef:
name: kubectl-deploy
runAfter:
- build-app
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
- name: left_pipeline
type: string
- name: right_pipeline
type: string
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/condition/pipelinerun-my.yaml
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/deploymen2.yaml "
- name: left_pipeline
value: “1”
- name: right_pipeline
value: “1”
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
timeout
pipeline/pipeline-timeout.yaml
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
runAfter:
- build-app
retries: 2
timeout: 1s
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
resources
pipeline /pipeline-resources.yaml
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
params
pipeline/pipeline-params.yaml
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
bundle
pipeline/bundle/build-push-kaniko.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-push-kaniko
spec:
resources:
inputs:
- name: workspace
type: git
outputs:
- name: builtImage
type: image
params:
- name: pathToDockerFile
description: The path to the dockerfile to build
default: /workspace/workspace/Dockerfile
- name: pathToContext
description: The build context used by Kaniko
default: /workspace/workspace
steps:
- name: build-and-push
image: registry.us-west-1.aliyuncs.com/hxpapp/kaniko-executor:latest
#env:
#- name: "DOCKER_CONFIG"
# value: "/tekton/home/.docker/"
args:
- --dockerfile=$(inputs.params.pathToDockerFile)
- --destination=$(outputs.resources.builtImage.url)
- --context=$(inputs.params.pathToContext)
- --oci-layout-path=$(inputs.resources.builtImage.path)
securityContext:
runAsUser: 0
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker/
volumes:
- name: kaniko-secret
secret:
secretName: registry-secret
items:
- key: .dockerconfigjson
path: config.json
tkn bundle push registry.cn-shanghai.aliyuncs.com/hxpdocker/build-push-kaniko:latest -f build-push-kaniko.yaml
pipeline/bundle/mypipeline.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mypipeline
spec:
tasks:
- name: build-app
taskRef:
name: build-push-kaniko
bundle: registry.cn-shanghai.aliyuncs.com/hxpdocker/build-push-kaniko:latest
resources:
inputs:
- name: workspace
resource: workspace
outputs:
- name: builtImage
resource: my-image
resources:
- name: workspace
type: git
- name: my-image
type: image
when
pipeline/when/pipeline-when.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mypipeline
spec:
tasks:
- name: build-app
when:
- input: "$(params.path)"
operator: in
values: ["README.md"]
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
- name: path
type: string
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/when/pipelinerun-my.yaml
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 "
- name: path
value: "README.md"
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
workspaces
pipeline/workspaces/task-build-push-kaniko.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-push-kaniko
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace/config
readOnly: false
resources:
inputs:
- name: workspace
type: git
outputs:
- name: builtImage
type: image
params:
- name: pathToDockerFile
description: The path to the dockerfile to build
default: /workspace/workspace/Dockerfile
- name: pathToContext
description: The build context used by Kaniko
default: /workspace/workspace
steps:
- name: build-and-push
image: registry.us-west-1.aliyuncs.com/hxpapp/kaniko-executor:latest
#env:
#- name: "DOCKER_CONFIG"
# value: "/tekton/home/.docker/"
args:
- --dockerfile=$(inputs.params.pathToDockerFile)
- --destination=$(outputs.resources.builtImage.url)
- --context=$(inputs.params.pathToContext)
- --oci-layout-path=$(inputs.resources.builtImage.path)
securityContext:
runAsUser: 0
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker/
volumes:
- name: kaniko-secret
secret:
secretName: registry-secret
items:
- key: .dockerconfigjson
path: config.json
pipeline/workspaces/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
resources:
inputs:
- name: image
type: image
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/workspaces/pipeline-workspaces.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mypipeline
spec:
tasks:
- name: build-app
taskRef:
name: build-push-kaniko
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: workspace
resource: workspace
outputs:
- name: builtImage
resource: my-image
- name: deploy-app
taskRef:
name: kubectl-deploy
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
params:
- name: script_body
value: $(params.script_body_pipeline)
params:
- name: script_body_pipeline
type: string
workspaces:
- name: source
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/workspaces/confimap-my.yaml
apiVersion: v1
data:
deployment.yaml: |
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
labels:
app: my-app
spec:
selector:
matchLabels:
app: my-app
replicas: 1
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: registry.cn-beijing.aliyuncs.com/hxpdocker/testimage
kind: ConfigMap
metadata:
name: my-configmap
pipeline/workspaces/pipelinerun-my.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: mypipeline-run
spec:
serviceAccountName: test-task-robot-git-ssh
pipelineRef:
name: mypipeline
workspaces:
- name: source
configmap:
name: my-configmap
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
results
pipeline/results/task-build-push-kaniko.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: build-push-kaniko
spec:
results:
- name: test
resources:
inputs:
- name: workspace
type: git
outputs:
- name: builtImage
type: image
params:
- name: pathToDockerFile
description: The path to the dockerfile to build
default: /workspace/workspace/Dockerfile
- name: pathToContext
description: The build context used by Kaniko
default: /workspace/workspace
steps:
- name: build-and-push
image: registry.us-west-1.aliyuncs.com/hxpapp/kaniko-executor:latest
#env:
#- name: "DOCKER_CONFIG"
# value: "/tekton/home/.docker/"
args:
- --dockerfile=$(inputs.params.pathToDockerFile)
- --destination=$(outputs.resources.builtImage.url)
- --context=$(inputs.params.pathToContext)
- --oci-layout-path=$(inputs.resources.builtImage.path)
securityContext:
runAsUser: 0
volumeMounts:
- name: kaniko-secret
mountPath: /kaniko/.docker/
- name: print-date-human-readable
image: bash:latest
script: |
#!/usr/bin/env bash
printf "true" > $(results.test.path)
#echo "true"> $(results.test.path)
cat $(results.test.path)
volumes:
- name: kaniko-secret
secret:
secretName: registry-secret
items:
- key: .dockerconfigjson
path: config.json
pipeline/results/pipeline-my.yaml
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
when:
- input: $(tasks.build-app.results.test)
operator: in
values: ["true"]
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
description
pipeline/pipeline-description.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: mypipeline
spec:
description: this is a test
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
finally
name
taskRef
pipeline/finally/task-finally.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: clean
spec:
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
kubectl delete deploy --all -n tekton
pipeline/finally/pipeline-my.yaml
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)
finally:
- name: clean
taskRef:
name: clean
params:
- name: script_body_pipeline
type: string
resources:
- name: workspace
type: git
- name: my-image
type: image
workspaces
params
pipeline/finally/workspaces/task-clean.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: clean
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/workspaces/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
resources:
inputs:
- name: image
type: image
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/workspaces/pipeline-my.yaml
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
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
params:
- name: script_body
value: $(params.script_body_pipeline)
finally:
- name: clean
taskRef:
name: clean
workspaces:
- name: shared-workspace
workspace: source
params:
- name: script_body
value: $(params.script_body_finally)
params:
- name: script_body_pipeline
type: string
- name: script_body_finally
type: string
workspaces:
- name: source
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/finally/workspaces/pipelinerun-my.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: mypipeline-run
spec:
serviceAccountName: test-task-robot-git-ssh
pipelineRef:
name: mypipeline
workspaces:
- name: source
configmap:
name: my-configmap
params:
- name: script_body_pipeline
value: "kubectl apply -f /workspace/workspace/deployment.yaml "
- name: script_body_finally
value: "kubectl delete -f /workspace/workspace/deployment.yaml "
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
taskSpec
pipeline/finally/taskSpec/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
resources:
inputs:
- name: image
type: image
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/taskSpec/pipeline-my.yaml
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
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
params:
- name: script_body
value: $(params.script_body_pipeline)
finally:
- name: clean
taskSpec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
workspaces:
- name: shared-workspace
workspace: source
params:
- name: script_body
value: $(params.script_body_finally)
params:
- name: script_body_pipeline
type: string
- name: script_body_finally
type: string
workspaces:
- name: source
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/finally/taskSpec/pipelinerun-my.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: mypipeline-run
spec:
serviceAccountName: test-task-robot-git-ssh
pipelineRef:
name: mypipeline
workspaces:
- name: source
configmap:
name: my-configmap
params:
- name: script_body_pipeline
value: "kubectl apply -f /workspace/workspace/deployment.yaml "
- name: script_body_finally
value: "kubectl delete -f /workspace/workspace/deployment.yaml "
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
when
pipeline/finally/when/task-clean.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: clean
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/when/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
resources:
inputs:
- name: image
type: image
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/when/pipeline-my.yaml
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
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
params:
- name: script_body
value: $(params.script_body_pipeline)
finally:
- name: clean
when:
- input: "$(params.path)"
operator: in
values: ["README.md"]
taskRef:
name: clean
workspaces:
- name: shared-workspace
workspace: source
params:
- name: script_body
value: $(params.script_body_finally)
params:
- name: script_body_pipeline
type: string
- name: script_body_finally
type: string
- name: path
type: string
workspaces:
- name: source
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/finally/when/pipelinerun-my.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: mypipeline-run
spec:
serviceAccountName: test-task-robot-git-ssh
pipelineRef:
name: mypipeline
workspaces:
- name: source
configmap:
name: my-configmap
params:
- name: script_body_pipeline
value: "kubectl apply -f /workspace/workspace/deployment.yaml "
- name: script_body_finally
value: "kubectl delete -f /workspace/workspace/deployment.yaml "
- name: path
value: "README.md"
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image
resources
pipeline/finally/resources/task-clean.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: clean
spec:
resources:
inputs:
- name: workspace
type: git
params:
- name: script_body
type: string
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/resources/task-kubectl-deploy.yaml
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: kubectl-deploy
spec:
workspaces:
- name: shared-workspace
mountPath: /workspace/workspace
params:
- name: script_body
type: string
resources:
inputs:
- name: image
type: image
steps:
- name: kubectl-deploy
image: registry.cn-shanghai.aliyuncs.com/hxpdocker/kubectl:latest
script: |
$(params.script_body)
pipeline/finally/resources/pipeline-my.yaml
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
workspaces:
- name: shared-workspace
workspace: source
resources:
inputs:
- name: image
resource: my-image
from:
- build-app
params:
- name: script_body
value: $(params.script_body_pipeline)
finally:
- name: clean
taskRef:
name: clean
resources:
inputs:
- name: workspace
resource: workspace
params:
- name: script_body
value: $(params.script_body_finally)
params:
- name: script_body_pipeline
type: string
- name: script_body_finally
type: string
workspaces:
- name: source
resources:
- name: workspace
type: git
- name: my-image
type: image
pipeline/finally/resources/pipelinerun-my.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: mypipeline-run
spec:
serviceAccountName: test-task-robot-git-ssh
pipelineRef:
name: mypipeline
workspaces:
- name: source
configmap:
name: my-configmap
params:
- name: script_body_pipeline
value: "kubectl apply -f /workspace/workspace/deployment.yaml "
- name: script_body_finally
value: "kubectl delete -f /workspace/workspace/deployment.yaml "
resources:
- name: workspace
resourceRef:
name: workspace
- name: my-image
resourceRef:
name: my-image