triggers: Polling a repository to detect changes and trigger a pipeline

To Poll a repository at a certain interval to look for any changes and trigger a pipelinerun/taskrun.

Use cases:

This can be done using a cronjob but could to a part of triggers. Similar Issue: https://github.com/tektoncd/triggers/issues/480

Proposal: To have this feature as a part of triggers. I did a poc around this where I have a new SyncRepo CRD

apiVersion: triggers.tekton.dev/v1alpha1
kind: SyncRepo
metadata:
  name: test
spec:
  repo: https://github.com/tektoncd/hub
  branch: main
  frequency: 3m
  binding: pipeline-binding
  template: pipeline-template

Approach:

  • This looks for changes on repository using GitHub Rest API and triggers a pipelines.
  • The API returns the response in json format for example or https://api.github.com/repos/sm43/hub/commits/tekton-ci
  • It uses trigger binding to get values from the json response and use them in the trigger template and triggers the pipelinerun.
  • Later it saves the last commit on which it was triggered and use it in next reconcilation to look for changes.

Things can be improved:

  • Support for private repositories
  • Gitlab also have similar API which we can use
  • We can also directly allow users to pass pipelineRef which can be directly used if a user doesn’t want to use TriggerBinding/TriggerTemplate
  • A user can provide multiple pipeline templates which can be triggered together

Available solution: There is an operator by Kevin https://github.com/bigkevmcd/tekton-polling-operator which polls a repo and create a pipelinerun/taskrun if something is changes. This is independent of TektonBinding and TektonTemplate, it take PipelineRef as input.

cc @vdemeester

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (10 by maintainers)

Most upvoted comments

@vdemeester I have working code that I’m literally just writing examples and docs for, that simplifies this to just a CR that detects changes in a ref in a git repository and sends a CloudEvent on change…not Tekton specific at all

I was thinking about this, part of the complexity of this is integrating with Triggers and TriggerTemplates, but maybe it shouldn’t, and instead, when it sees a new commit, it should send the commit as a “hook” to an EventListener, it would be “internal” ?

We should also probably support “any” git repositories (and not only github/gitlab/…).

Are there any news regarding this feature? We also cannot use webhooks because of a corporate proxy 😕 This issue is now 2 years old …