pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

allow more complex when conditions, minimally regex

Open itewk opened this issue 4 years ago • 25 comments

Feature request

currently the when statement that replaced the Condition CRD only has the ability to check if a given string is in a list of other strings. This is limiting.

Need the ability to at the least do pattern matching, ex, regex.

Use case

Transitioning from a Jenkins pipeline to a Tekton pipeline. In Jenkins have when condition on steps to check the branch and compare it against patterns to decide whether to exuecute the step. IE, for "PROD deploy" step verify that on the main or release/.* branch and for "Merge Request Deploy" check feature/.*. When translating to Tekton there is no way to do this blocking our ability to translate the logic.

Other

This is the problem bit, that it has a hard coded == https://github.com/tektoncd/pipeline/blob/master/pkg/apis/pipeline/v1beta1/when_types.go#L82. Need the ability to control that operation, or just change that op to a regex match which then will work for == as well.

Ideally this wouldn't be hard coded and rather any arbitrary function that returns true/false could be supplied to make the deicion to future proof against any possible future ways someone may want to add a condition to a step.

itewk avatar Oct 28 '20 20:10 itewk

For now, you could possibly solve your use case by creating a Task that compares a branch Param against a pattern Param and produces a Result indicating whether it matches....then use that Result in WhenExpressions to guard the subsequent Tasks

Separately, one alternative for supporting regex matching in WhenExpressions is by adding another Operator (maybe Matches) instead of modifying the In and NotIn Operators

jerop avatar Oct 29 '20 03:10 jerop

@jerop thanks for the work around idea. I will give it a try and report back. and I like the new operator idea.

itewk avatar Oct 29 '20 11:10 itewk

Definitely need more flexibility w/ WhenExpressions:

All standard operators should be supported (in, not in, >, <, >=, <= and ==/!= aliased to in/notin just to be friendly

Ideally just supporting an "expression" literally via CEL (+regex like the op requested) would be great to. Really can just open it up to more possibilities you can't predict. Keep it as open as possible. https://github.com/tektoncd/pipeline/issues/2812

Here is my scenario:

I have a task who's result is a metric. Then whether or not a subsequent task proceeds is based if that metric meets a threshold. (think, <=, >=, <, > etc)

I guess I could change the task's "result" to be an "interpretation" of that metric that is compatible with what WhenExpression currently supports (or create an intermediary Task that interprets the result, then the interpreters result becomes the input to the WhenExpression) but this all seems like hoops to jump through.

I think of tasks like functions. the caller (pipeline) makes the interpretation of the result from the call to the function, not the function itself. The caller in this case is the pipeline and the function is the task who's "output/result" is a metric. I want to be able to re-use my task that "does X and returns metric" and not tightly couple it to the context its used in by doing the interpretation of the result itself. In diff contexts (pipelines) where/when the task is invoked, the metric result can be interpreted in diff ways.

Do be able to do this requires a more flexible "interpreter" mechanism if WhenExpression is the only means currently to do it now (outside of deprecated conditions) or intermediary "result generator/interpretor tasks". Its just too limited with in/notin imho

leverage the power of all the various expression dsls out there to open it up to a "context object" that contains all the pipeline params, task results and just let the operator (user) craft an expression of what they need to evaluate.

bitsofinfo avatar Nov 25 '20 17:11 bitsofinfo

Also the default behavior of:

If all the WhenExpressions evaluate to True

Needs any option to toggle the behavior to be:

If ANY of the WhenExpressions evaluate to True

I have this scenario where I have multiple spawned tasks, and if any ONE of them fails, I need something else to run.

bitsofinfo avatar Dec 03 '20 15:12 bitsofinfo

https://github.com/tektoncd/pipeline/issues/3591

bitsofinfo avatar Dec 03 '20 16:12 bitsofinfo

@itewk @bitsofinfo check out the newly-added common expression language custom task which may be helpful for your use cases

jerop avatar Jan 21 '21 20:01 jerop

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 Apr 21 '21 21:04 tekton-robot

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 May 21 '21 21:05 tekton-robot

/remove-lifecycle rotten

bitsofinfo avatar May 25 '21 12:05 bitsofinfo

Is this being actively worked on somewhere? Or is this something I could help out with? We would love to have this natively in Tekton for our users to write their own when expressions with basic regex matching rather than deal with a custom task.

Evertras avatar Aug 17 '21 09:08 Evertras

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 Nov 15 '21 10:11 tekton-robot

/remove-lifecycle stale

bitsofinfo avatar Nov 17 '21 18:11 bitsofinfo

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 Feb 15 '22 18:02 tekton-robot

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 17 '22 18:03 tekton-robot

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.

tekton-robot avatar Apr 16 '22 19:04 tekton-robot

@tekton-robot: Closing this issue.

In response to this:

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.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Apr 16 '22 19:04 tekton-robot

/reopen

Its hard to believe this is not a feature, WhenExpressions are so limited limited without it, honestly its hard be believe this wasn't part of the initial deployment.

jacobbrozenick avatar Sep 14 '22 22:09 jacobbrozenick

@jacobbrozenick: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Its hard to believe this is not a feature, WhenExpressions are so limited limited without it, honestly its hard be believe this wasn't part of the initial deployment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Sep 14 '22 22:09 tekton-robot

/reopen

bitsofinfo avatar Sep 15 '22 15:09 bitsofinfo

@bitsofinfo: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Sep 15 '22 15:09 tekton-robot

/remove-lifecycle rotten

bitsofinfo avatar Sep 15 '22 15:09 bitsofinfo

/reopen

bitsofinfo avatar Sep 15 '22 15:09 bitsofinfo

@bitsofinfo: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Sep 15 '22 15:09 tekton-robot

reopening on behalf of @bitsofinfo

/reopen

jerop avatar Sep 15 '22 16:09 jerop

@jerop: Reopened this issue.

In response to this:

reopening on behalf of @bitsofinfo

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

tekton-robot avatar Sep 15 '22 16:09 tekton-robot

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 14 '22 16:12 tekton-robot

/remove-lifecycle stale

bitsofinfo avatar Dec 16 '22 22:12 bitsofinfo

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 Mar 16 '23 23:03 tekton-robot

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 Apr 15 '23 23:04 tekton-robot

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.

tekton-robot avatar May 16 '23 00:05 tekton-robot