4.8. 在 Pipeline 中添加触发器
在组装并启动应用程序 Pipeline 后,添加 TriggerBindings、TriggerTemplates 和 EventListener 以捕获 GitHub 事件。
流程
复制以下
TriggerBinding
YAML 示例文件的内容并保存:apiVersion: triggers.tekton.dev/v1alpha1 kind: TriggerBinding metadata: name: vote-app spec: params: - name: git-repo-url value: $(body.repository.url) - name: git-repo-name value: $(body.repository.name) - name: git-revision value: $(body.head_commit.id)
创建
TriggerBinding
:$ oc create -f <triggerbinding-yaml-file-name.yaml>
或者,您可以直接从
pipelines-tutorial
Git 存储库创建TriggerBinding
:$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/release-tech-preview-1/03_triggers/01_binding.yaml
复制以下
TriggerTemplate
YAML 示例文件的内容并保存:apiVersion: triggers.tekton.dev/v1alpha1 kind: TriggerTemplate metadata: name: vote-app spec: params: - name: git-repo-url description: The git repository url - name: git-revision description: The git revision default: master - name: git-repo-name description: The name of the deployment to be created / patched resourcetemplates: - apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: name: $(params.git-repo-name)-git-repo-$(uid) spec: type: git params: - name: revision value: $(params.git-revision) - name: url value: $(params.git-repo-url) - apiVersion: tekton.dev/v1alpha1 kind: PipelineResource metadata: name: $(params.git-repo-name)-image-$(uid) spec: type: image params: - name: url value: image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/$(params.git-repo-name):latest - apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: build-deploy-$(params.git-repo-name)-$(uid) spec: serviceAccountName: pipeline pipelineRef: name: build-and-deploy resources: - name: git-repo resourceRef: name: $(params.git-repo-name)-git-repo-$(uid) - name: image resourceRef: name: $(params.git-repo-name)-image-$(uid) params: - name: deployment-name value: $(params.git-repo-name)
创建
TriggerTemplate
:$ oc create -f <triggertemplate-yaml-file-name.yaml>
另外,您还可以从
pipelines-tutorial
Git 存储库直接创建TriggerTemplate
:$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/release-tech-preview-1/03_triggers/02_template.yaml
复制以下
EventListener
YAML 示例文件的内容并保存:apiVersion: triggers.tekton.dev/v1alpha1 kind: EventListener metadata: name: vote-app spec: serviceAccountName: pipeline triggers: - bindings: - name: vote-app template: name: vote-app
创建
EventListener
:$ oc create -f <eventlistener-yaml-file-name.yaml>
或者,您可以直接从
pipelines-tutorial
Git 存储库创建EvenListener
:$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/release-tech-preview-1/03_triggers/03_event_listener.yaml
将 EventListener 服务以 OpenShift Container Platform 路由的形式公开,以便公众可以访问它:
$ oc expose svc el-vote-app