3.4. 使用匿名 Git 克隆指定远程管道或任务
您可以使用 Git 解析器从 Git 存储库访问远程管道或任务。存储库必须包含定义管道或任务的 YAML 文件。对于匿名访问,您可以使用解析器克隆存储库,而无需身份验证凭证。
3.4.1. 为匿名 Git 克隆配置 Git 解析器
如果要使用匿名 Git 克隆,您可以配置默认的 Git 修订、获取超时和默认存储库 URL,以便从 Git 存储库拉取远程管道和任务。
流程
要编辑
TektonConfig
自定义资源,请输入以下命令:Copy to Clipboard Copied! Toggle word wrap Toggle overflow oc edit TektonConfig config
$ oc edit TektonConfig config
在
TektonConfig
自定义资源中,编辑pipeline.git-resolver-config
spec:Copy to Clipboard Copied! Toggle word wrap Toggle overflow apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: pipeline: git-resolver-config: default-revision: main fetch-timeout: 1m default-url: https://github.com/tektoncd/catalog.git
apiVersion: operator.tekton.dev/v1alpha1 kind: TektonConfig metadata: name: config spec: pipeline: git-resolver-config: default-revision: main
1 fetch-timeout: 1m
2 default-url: https://github.com/tektoncd/catalog.git
3
3.4.2. 使用 Git 解析器为匿名克隆指定远程管道或任务
在创建管道运行时,您可以使用匿名克隆从 Git 存储库指定远程管道。在创建管道或任务运行时,您可以从 Git 仓库指定远程任务。
流程
要从 Git 仓库指定远程管道或任务,请在
pipelineRef
或taskRef
spec 中使用以下引用格式:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ... ...
# ... resolver: git params: - name: url value: <git_repository_url> - name: revision value: <branch_name> - name: pathInRepo value: <path_in_repository> # ...
表 3.4. Git 解析器支持的参数 参数 描述 示例值 url
使用匿名克隆时存储库的 URL。
https://github.com/tektoncd/catalog.git
revision
存储库中的 Git 修订。您可以指定分支名称、标签名称或提交 SHA 哈希。
aeb957601cf41c012be462827053a21a420befca
main
v0.38.2
pathInRepo
存储库中的 YAML 文件的路径名称。
task/golang-build/0.3/golang-build.yaml
注意要匿名克隆和获取存储库,请使用
url
参数。不要同时指定url
参数和repo
参数。如果管道或任务需要额外的参数,请在
params
中提供这些参数。
以下示例管道运行引用 Git 存储库中的远程管道:
apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: git-pipeline-reference-demo spec: pipelineRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - name: revision value: main - name: pathInRepo value: pipeline/simple/0.1/simple.yaml params: - name: name value: "testPipelineRun" - name: sample-pipeline-parameter value: test
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: git-pipeline-reference-demo
spec:
pipelineRef:
resolver: git
params:
- name: url
value: https://github.com/tektoncd/catalog.git
- name: revision
value: main
- name: pathInRepo
value: pipeline/simple/0.1/simple.yaml
params:
- name: name
value: "testPipelineRun"
- name: sample-pipeline-parameter
value: test
以下示例管道引用 Git 存储库中的远程任务:
apiVersion: tekton.dev/v1 kind: Pipeline metadata: name: pipeline-with-git-task-reference-demo spec: tasks: - name: "git-task-reference-demo" taskRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - name: revision value: main - name: pathInRepo value: task/git-clone/0.6/git-clone.yaml params: - name: sample-task-parameter value: test
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: pipeline-with-git-task-reference-demo
spec:
tasks:
- name: "git-task-reference-demo"
taskRef:
resolver: git
params:
- name: url
value: https://github.com/tektoncd/catalog.git
- name: revision
value: main
- name: pathInRepo
value: task/git-clone/0.6/git-clone.yaml
params:
- name: sample-task-parameter
value: test
以下示例任务运行引用 Git 存储库中的远程任务:
apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: name: git-task-reference-demo spec: taskRef: resolver: git params: - name: url value: https://github.com/tektoncd/catalog.git - name: revision value: main - name: pathInRepo value: task/git-clone/0.6/git-clone.yaml params: - name: sample-task-parameter value: test
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: git-task-reference-demo
spec:
taskRef:
resolver: git
params:
- name: url
value: https://github.com/tektoncd/catalog.git
- name: revision
value: main
- name: pathInRepo
value: task/git-clone/0.6/git-clone.yaml
params:
- name: sample-task-parameter
value: test