triggers icon indicating copy to clipboard operation
triggers copied to clipboard

Polling a repository to detect changes and trigger a pipeline

Open sm43 opened this issue 4 years ago • 15 comments

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

Use cases:

  • Some users might not have permission to setup a webhook so this could be helpful to trigger a pipelinerun/taskrun after some changes.
  • another use case https://github.com/tektoncd/triggers/issues/480#issuecomment-620605920

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

sm43 avatar Jul 30 '21 05:07 sm43

@dibyom @wlynch @savitaashture @khrm let me know what do you think? :upside_down_face:

sm43 avatar Jul 30 '21 05:07 sm43

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

vdemeester avatar Jul 30 '21 09:07 vdemeester

We discussed this at the last WG and decided that the next steps would be to open up a TEP with the problem statement/use cases so that we can gather more requirements/feedback for this feature.

dibyom avatar Aug 06 '21 15:08 dibyom

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" ?

bigkevmcd avatar Sep 02 '21 08:09 bigkevmcd

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" ?

that is definitely an approach we should consider!

dibyom avatar Sep 23 '21 18:09 dibyom

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale with a justification. Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

tekton-robot avatar Dec 22 '21 18:12 tekton-robot

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: #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

found this error : " no matches for kind "SyncRepo" in version "triggers.tekton.dev/v1alpha1""

tisaiful31 avatar Jan 18 '22 14:01 tisaiful31

[…] found this error : " no matches for kind "SyncRepo" in version "triggers.tekton.dev/v1alpha1""

@tisaiful31 this is to be expected, what I wrote is just a proposal, that's still being discussed and thought trough.

vdemeester avatar Jan 20 '22 09:01 vdemeester

@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

bigkevmcd avatar Jan 20 '22 10:01 bigkevmcd

@bigkevmcd That sounds like a really nice solution to this

dibyom avatar Jan 20 '22 18:01 dibyom

There is a implementation that works in combination with FluxCD https://github.com/jquad-group/pipeline-trigger-operator

They use the Flux Sourcecontroller to track changes.

triantium avatar Feb 18 '22 12:02 triantium

@triantium that is a nice idea, it could of course be connected to triggers via flux notifications like this https://bigkevmcd.github.io/tekton/flux/notifications/2020/12/06/flux-tekton.html

bigkevmcd avatar Feb 18 '22 19:02 bigkevmcd

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten with a justification. Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle rotten

Send feedback to tektoncd/plumbing.

tekton-robot avatar Mar 20 '22 19:03 tekton-robot

/area roadmap

vdemeester avatar Feb 15 '23 15:02 vdemeester

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

Syntax3rror404 avatar Nov 07 '23 12:11 Syntax3rror404