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

Warn user when on-cel-expression is used alongside on-target-branch and on-event #1974

Open
chmouel opened this issue Mar 5, 2025 · 1 comment

Comments

@chmouel
Copy link
Member

chmouel commented Mar 5, 2025

Description:
When using both on-event and on-target-branch annotations, it's important to note that if an on-cel-expression annotation is also present, the on-cel-expression will take precedence. This means that the conditions specified in on-event and on-target-branch will be ignored.

To avoid confusion, we should warn users in both the user events namespace and the controller logs when they define a PipelineRun that includes both on-cel-expression and either on-event or on-target-branch.

Example Scenario:

metadata:
  name: example-pipeline
  annotations:
    pipelinesascode.tekton.dev/on-event: "[pull_request]"
    pipelinesascode.tekton.dev/on-target-branch: "[main]"
    pipelinesascode.tekton.dev/on-cel-expression: |
      event == "pull_request" && target_branch == "main" && source_branch == "feature"

In this example, even though on-event and on-target-branch are specified, the on-cel-expression will take precedence. The PipelineRun will only be triggered if the event is a pull request targeting the main branch and the source branch is feature.

Proposed Solution:

  1. User Events Namespace Warning:

    • When a PipelineRun is created with both on-cel-expression and on-event/on-target-branch, a warning event should be emitted in the user's namespace. This warning should clearly state that on-cel-expression will override the other annotations.

    Example warning message:

    Warning: The PipelineRun "example-pipeline" has both `on-cel-expression` and `on-event`/`on-target-branch` annotations. The `on-cel-expression` will take precedence, and the other annotations will be ignored.
    
  2. Controller Logs Warning:

    • Similarly, a warning should be logged in the Pipelines-as-Code controller logs to indicate that the user has defined conflicting annotations. This will help administrators and developers debug issues related to PipelineRun matching.

    Example log message:

    WARN: PipelineRun "example-pipeline" in namespace "user-namespace" has conflicting annotations (`on-cel-expression` and `on-event`/`on-target-branch`). `on-cel-expression` will take precedence.
    

Why This Matters:

  • User Awareness: Users may not realize that on-cel-expression overrides other annotations, leading to unexpected behavior in their CI pipelines. A clear warning in their namespace will help them understand why their PipelineRun is not being triggered as expected.
  • Debugging: Logging this warning in the controller logs will assist administrators in identifying and resolving issues related to PipelineRun configurations.

Next Steps:

  • Implement the warning mechanism in the Pipelines-as-Code controller to emit events in the user's namespace and log warnings when conflicting annotations are detected.
  • Update the documentation to explicitly mention this behavior and the warnings that users can expect.
@chmouel
Copy link
Member Author

chmouel commented Mar 5, 2025

@chmouel chmouel assigned chmouel and unassigned chmouel Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant