Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tekton Bitbucket Event listener only run when the master branch is changed #1607

Open
tppalani opened this issue Jun 7, 2023 · 7 comments
Open
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@tppalani
Copy link

tppalani commented Jun 7, 2023

Hi Team,

  1. I have successfully configured Event listener with bitbucket server.
  2. But the problem is when new changes has been detected inside my repository pipeline getting triggered, Instead i want trigger the pipeline when the changes has merged or committed in only master branch.

Here the code.

Trigger-binding.yaml

apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
  name: bitbucket-trigger-binding
  namespace: devops
spec:
  params:
  - name: gitrevision
    value: $(body.changes[0].ref.displayId)
  - name: gitrepositoryurl
    value: $(body.repository.links.clone[1].href)

Eventlistener.yaml

apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
  name: bitbucket-event-listener
  namespace: devops
spec:
  serviceAccountName: tekton-triggers-example-sa
  triggers:
    - name: bitbucket-trigger-binding
      interceptors:
        - ref:
            name: "bitbucket"
          params:
            - name: secretRef
              value: null
            - name: eventTypes
              value:
                - repo:refs_changed
      bindings:
        - ref: bitbucket-trigger-binding
      template:
        ref: bitbucket-trigger-template

Trigger template

apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerTemplate
metadata:
  name: bitbucket-trigger-template
  namespace: devops
spec:
  params:
  - name: revision
  - name: url
    default: "https://bitbucket.tekton-poc.git"
  - name: flags
    default: --insecure
  resourcetemplates:
  - apiVersion: tekton.dev/v1beta1
    kind: PipelineRun
    metadata:
      generateName: trigger-eventlistener-
    spec:
      pipelineRef:
        name: test-pipeline-triggers
      podTemplate:
        securityContext:
          runAsUser: 0
          fsGroup: 1001
      params:
        - name: repo_full_name
          value: "tekton-poc"
        - name: revision
          value: "eventlistener-trigger"
        - name: subdirectory
          value: "source"
        - name: url
          value: "https://bitbucket.tekton-poc.git"
@tppalani
Copy link
Author

tppalani commented Jun 9, 2023

Hi @savitaashture can you please help me on this.

@vinamra28
Copy link
Member

hi @tppalani, probably one interceptor won't work alone, you'll have to use CEL expressions as well in order to filter the request based on custom requirements such as

    - ref:
        name: "cel"
      params:
        - name: "filter"
          value: body.ref == 'refs/heads/main'

so your resultant EventListener would turn up as

apiVersion: triggers.tekton.dev/v1beta1
kind: EventListener
metadata:
  name: bitbucket-event-listener
  namespace: devops
spec:
  serviceAccountName: tekton-triggers-example-sa
  triggers:
    - name: bitbucket-trigger-binding
      interceptors:
        - ref:
            name: "bitbucket"
          params:
            - name: secretRef
              value: null
            - name: eventTypes
              value:
                - repo:refs_changed
        - ref:
              name: "cel"
           params:
            - name: "filter"
              value: body.ref == 'refs/heads/main'
      bindings:
        - ref: bitbucket-trigger-binding
      template:
        ref: bitbucket-trigger-template

@dibyom @savitaashture @khrm please correct me if I missed something here

@tppalani
Copy link
Author

Hi @vinamra28 Thanks for the quick response. As per your instruction i have updated my event listener yaml file but now the pipeline is not getting triggered if target branch updated.

@dibyom
Copy link
Member

dibyom commented Jun 14, 2023

@tppalani just making sure - @vinamra28 's example used value: body.ref == 'refs/heads/main' - if you branch name is master, you'd want to use refs/heads/master.
If that is not the issue, then could you please provide logs from the eventlistener?

@tekton-robot
Copy link

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 tekton-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 12, 2023
@tekton-robot
Copy link

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 tekton-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 12, 2023
@tekton-robot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen with a justification.
Mark the issue as fresh with /remove-lifecycle rotten with a justification.
If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/close

Send feedback to tektoncd/plumbing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

4 participants