openshift-pipelines / pipelines-as-code

Pipelines-as-Code for Tekton
https://pipelinesascode.com
Apache License 2.0
138 stars 84 forks source link

CEL Expression doesn't seem to work with Bitbucket server #1677

Open Mikkelmedetk opened 7 months ago

Mikkelmedetk commented 7 months ago

Hi,

I've been experimenting a bit with Pipelines as Code together with bitbucket-server.

But it doesn't seem to work with CEL-Expression annotation: ... annotations: pipelinesascode.tekton.dev/on-cel-expression: event == "push" && target_branch == "master" ...

This is what i observe on the pipeline-as-a-code controller logs {"level":"info","ts":"2024-05-03T08:13:15.037Z","logger":"pipelinesascode","caller":"bitbucketserver/bitbucketserver.go:174","msg":"Using PipelineRun definition from source pull request SHA: e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"} {"level":"info","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"matcher/annotation_matcher.go:133","msg":"matching pipelineruns to event: URL=https://REDACTED/projects/REDACTED/repos/REDACTED.REDACTED, target-branch=refs/heads/master, source-branch=refs/heads/master, target-event=push","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"} {"level":"error","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"matcher/annotation_matcher.go:172","msg":"there was an error evaluating the CEL expression, skipping: json: cannot unmarshal string into Go value of type map[string]interface {}","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED","stacktrace":"github.com/openshift-pipelines/pipelines-as-code/pkg/matcher.MatchPipelinerunByAnnotation\n\t/go/src/github.com/openshift-pipelines/pipelines-as-code/pkg/matcher/annotation_matcher.go:172\ngithub.com/openshift-pipelines/pipelines-as-code/pkg/pipelineascode.(*PacRun).getPipelineRunsFromRepo\n\t/go/src/github.com/openshift-pipelines/pipelines-as-code/pkg/pipelineascode/match.go:195\ngithub.com/openshift-pipelines/pipelines-as-code/pkg/pipelineascode.(*PacRun).matchRepoPR\n\t/go/src/github.com/openshift-pipelines/pipelines-as-code/pkg/pipelineascode/matc... {"level":"warn","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"matcher/annotation_matcher.go:200","msg":"cannot match pipeline from payload to a pipelinerun in .tekton/ dir","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"} {"level":"warn","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"matcher/annotation_matcher.go:201","msg":"payload target event is with source branch refs/heads/master and target branch master","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"} {"level":"warn","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"matcher/annotation_matcher.go:202","msg":"available configuration of the PipelineRuns annotations in .tekton/ dir","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"} {"level":"warn","ts":"2024-05-03T08:13:15.607Z","logger":"pipelinesascode","caller":"events/emit.go:50","msg":"cannot match pipeline from payload to a pipelinerun in .tekton/ dir, event=, branch=master","provider":"bitbucket-server","event-id":"cc7d5e22-ef40-4575-bd18-d9eb4a10cd70","event-sha":"e516130c8cf654f321c0b0ac7b4011c9ad4b3bd9","event-type":"","namespace":"REDACTED"}

FM-githubcom commented 5 months ago

Same issue. Did you find a solution?

enarha commented 5 months ago

I'm just starting to look into that issue. I'll follow up with updates here.

Mikkelmedetk commented 5 months ago

Same issue. Did you find a solution?

No but looks like Emil will look into it :)

enarha commented 4 months ago

So I tested that and it worked. There are issues with file and path matching from the CEL expression with BitBucket, but that specific case worked. Here is the annotation I've used: pipelinesascode.tekton.dev/on-cel-expression: event == "pull_request" && target_branch == "main".

Few notes: First I'm testing with the most recent PAC version if you are willing to give it another try. I see some changes around that code, so there is a chance the issue was fixed.

Second, I'm testing with "Bitbucket Data Center" which is the successor of Bitbucket Server (not supported anymore).

Last thing, that error from the log seems suspicions: "there was an error evaluating the CEL expression, skipping: json: cannot unmarshal string into Go value of type map[string]interface {}". To me it sounds more like an issue with the yaml file. @Mikkelmedetk can you please share you pipelinerun manifest. Obviously feel free to obscure names/data, but please preserve the structure.

crikke commented 3 months ago

Had the same issue however it works when using event == "pull_request" but not with event == "push" The version of pac installed is 1.15.1

Edit: Still getting the issues when trying to check if file has changed with the following cel: pipelinesascode.tekton.dev/on-cel-expression: files.all.exists(x, x.matches('tmp/'))

I guess this is something that does not work with bitbucket since it seems like the webhook does not contain files changed unlike the github webhook. See here: https://community.atlassian.com/t5/Bitbucket-questions/WebHook-with-file-changes/qaq-p/770231

If this is the case I would suggest updating the documentation with a note that this is not supported for bitbucket