CI&CD
Git代码仓库
Drone
关联GOGS
Jenkins安装
Jenkins问题
JDK及Maven安装
插件安装
创建示例项目
CI流程
Tekton安装
tekton yaml文件
dashboard yaml文件
trigger yaml文件
Tekton使用(demo)
ArgoCD安装
ArgoCD使用
Tekton结合ArgoCD流水线
git-clone.yaml
docker-build.yaml
git-docker-build-pipline.yaml
helm-change-config.yaml
webhook触发器
本文档使用MrDoc发布
返回首页
-
+
webhook触发器
2023年6月19日 17:53
admin
#原理 ![](/media//202306/2023-06-20130603457670.png) --- #资料 https://blog.csdn.net/u013276277/article/details/107192079 https://blog.csdn.net/weixin_42574058/article/details/126834111 --- #1、部署tekton trigger ##[安装Trigger](http://baodoc.frp.bao-server.club:22080/project/56/597/ "安装Trigger") --- #2、创建yaml文件 vim git-docker-listener.yaml --- apiVersion: triggers.tekton.dev/v1alpha1 kind: TriggerTemplate metadata: name: git-template spec: params: # 参数的定义,从外部接收的参数 - name: gitrevision - name: gitrepositoryurl resourcetemplates: - apiVersion: tekton.dev/v1alpha1 kind: PipelineRun #触发类型:TaskRun、PipelineRun metadata: generateName: gitlab-run- # TaskRun 名称前缀 spec: #serviceAccountName: tekton-build-sa pipelineRef: name: git-docker-build #触发的 pipeline workspaces: - name: shared-data #workspaces volumeClaimTemplate: spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi #- name: go-repo-pvc # persistentVolumeClaim: # claimName: go-repo-pvc params: #git仓库url - name: repo-url value: http://192.168.31.49:6000/bao/projiect.git #git仓库分支 - name: branch-name value: master #生成的镜像 - name: harbor-image value: 192.168.31.49:81/library/test-nginx:$(params.gitrevision)" #推送的harbor仓库地址 - name: harbor-ip value: $(params.gitrepositoryurl) ------------------------ #TriggerBinding接收从EventListener传递过来的参数,然后传给TriggerTemplate,在TriggerTemplate上实例化资源对象 #TriggerBinding提供TriggerTemplate需要的参数,参数以key-value的方式存储并传递。其中的value是通过$()中包裹的JSONPath表达式来提取 apiVersion: triggers.tekton.dev/v1alpha1 kind: TriggerBinding metadata: name: pipeline-binding spec: params: - name: gitrevision # 参数的定义,从外部接收的参数 #value: 1.20.1 value: $(body.ref) #根据git提交的tag,设定版本号 #git tag v1.2 -m "备注信息" #git push -u origin master v1.2 - name: gitrepositoryurl value: 192.168.31.49:81 --- apiVersion: triggers.tekton.dev/v1alpha1 kind: EventListener metadata: name: git-template-listener spec: # from examples/role-resources/servicaccount.yaml serviceAccountName: tekton-triggers-example-sa triggers: - name: git-template-trigger bindings: # 关联TriggerBinding - name: pipeline-binding #- ref: pipeline-binding template: # 关联TriggerTemplate name: git-template --- apiVersion: v1 kind: Secret metadata: name: tekton-triggers-example-secret type: Opaque stringData: secretToken: "1qaz@WSX" #定义git的token --- apiVersion: v1g kind: ServiceAccount metadata: name: tekton-triggers-example-sa secrets: - name: tekton-triggers-example-secret --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: tekton-triggers-example-binding subjects: - kind: ServiceAccount name: tekton-triggers-example-sa roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: tekton-triggers-example-minimal --- kind: Role apiVersion: rbac.authorization.k8s.io/v1 metadata: name: tekton-triggers-example-minimal rules: # Permissions for every EventListener deployment to function - apiGroups: ["triggers.tekton.dev"] resources: ["eventlisteners", "triggerbindings", "triggertemplates"] verbs: ["get"] - apiGroups: [""] # secrets are only needed for Github/Gitlab interceptors, serviceaccounts only for per trigger authorization resources: ["configmaps", "secrets", "serviceaccounts"] verbs: ["get", "list", "watch"] # Permissions to create resources in associated TriggerTemplates - apiGroups: ["tekton.dev"] resources: ["pipelineruns", "pipelineresources", "taskruns"] verbs: ["create"] --- #3、创建EventListener ingress对象 ####为了能够让集群外gitlab访问至集群内eventlistener,需要把eventlistener通过ingress暴露在集群外。 ####查看已创建的eventlistener kubectl get eventlistener -A ####查看svc kubectl get svc -A | grep listener --- vim ingress-el.yaml --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: git-listen-ingress namespace: default # annotations: # kubernetes.io/ingress.class: nginx spec: rules: - http: paths: - path: /git-listen backend: serviceName: el-git-template-listener servicePort: 8080 --- #4、调用测试 curl -v -H 'Content-Type: application/json' --data '{"gitrevision": "1.0.3","gitrepositoryurl": "192.168.31.49:81"}' http://192.168.31.49/git-listen ![](/media//202306/2023-06-20151714367734.png) ![](/media//202306/2023-06-20151741041725.png)
分享到: