一、定义PipelineResource
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
name: resource-git-for-maven-build
(resource开头方便之后一看到,就知道是一个resource)
(在使用TaskRun或者PipelineRun的时候我们可以将其“注入”)
(当然我们可以在TaskRun或者PipelineRun中直接将Resource绑定在Task上,而不单独写这么一部分yaml)
spec:
type: git
params:
- name: url
value: https://github.com/pwplusnick/openwhisk-devtools.git
- name: revison
value: refs/heads/master
二、定义Task
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: task-build-jar-from-git-source(task开头方便之后一看到,就知道是一个task)
spec:
inputs:(可选的,可以是一系列参数[params],也可以是资源。这里需要Github的代码作为资源[resources],这里这是占位,后续“绑定”资源)
resources:
- name: source-fed-to-task(与TaskRun中input name一致)
type: git
steps:
- name: list-source
image: ubuntu
command:
- bash
args:
- -c
- |
ls -R $(inputs.resources.source-fed-to-task.path)/../
- name: build-with-maven
image: maven
command:
- mvn
args:
- -f
- $(inputs.resources.source-fed-to-task.path)/maven-java(这里有pom文件)
- package
- name: list-result
image: ubuntu
command:
- bash
args:
- -c
- |
ls -laR $(inputs.resources.source-fed-to-task.path)/maven-java/target/(看一下结果)
三、定义TaskRun
3.1 绑定PipelineResource的情况
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
name: taskrun-build-jar-from-git-source(可用于与tkn交互)
spec:
taskRef:
name: task-build-jar-from-git-source(使用name绑定Task)
inputs:
resources:
- name: source-fed-to-task(与Task的input指定的name一致——关联)
resourceRef:
name: resource-git-for-maven-build(注入,使用name绑定PipelineResource)
kc apply -f 运行
<问题排查相关>
可能能用到的命令:
kubectl get pods -A
tkn tr desc taskrun-build-jar-from-git-source
kubectl get taskruns taskrun-build-jar-from-git-source -o yaml
tkn tr logs -f taskrun-build-jar-from-git-source
tkn t logs -f task-build-jar-from-git-source
tkn tr cancel taskrun-build-jar-from-git-source
tkn tr delete -f taskrun-build-jar-from-git-source
tkn t delete -f task-build-jar-from-git-source
kc apply -f pipeline-maven-build-jar-from-git-source.yaml
webhook有检查配置文件的作用:
</问题排查相关>
3.2 运行验证
kubectl get taskruns taskrun-build-jar-from-git-source -o yaml
3.3 成功
2020/1/17补充:路径问题
版权声明:本文为HaixWang原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。