Skip to content

doc: Added Special CEL Expr in Filter Condition doc #5850

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

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions docs/user-guide/global-configurations/filter-condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Using filter conditions, you can control the progression of events. Here are a f
* Images containing the label "test" should not be eligible for deployment in production environment
* Only images having tag versions greater than v0.7.4 should be eligible for deployment
* Images hosted on Docker Hub should be eligible but not the rest
* Only images derived from master branch should be eligible for production deployment (see [example](#scenario-2))

---

Expand Down Expand Up @@ -55,17 +56,17 @@ You must have application(s) with CI-CD workflow(s) configured

![Figure 5: Selecting Environment(s) from Cluster(s)](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/environment-selection.jpg)

{% hint style="info" %}
Since an application can have more than one environment, the filter conditions apply only to the environment you chose in the **Apply to** section. If you create a filter condition without choosing an application or environment, it will not apply to any of your pipelines.
{% endhint %}
{% hint style="info" %}
Since an application can have more than one environment, the filter conditions apply only to the environment you chose in the **Apply to** section. If you create a filter condition without choosing an application or environment, it will not apply to any of your pipelines.
{% endhint %}

6. Click **Save**. You have successfully created a filter.

![Figure 6: Success Toast](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/filter-created.jpg)

{% hint style="warning" %}
If you create filters using CEL expressions that result in a conflict (i.e., passing and failing of the same image), fail will have higher precedence
{% endhint %}
{% hint style="warning" %}
If you create filters using CEL expressions that result in a conflict (i.e., passing and failing of the same image), fail will have higher precedence
{% endhint %}

---

Expand All @@ -78,6 +79,8 @@ Here's a sample pipeline we will be using for our explanation of [pass condition

### Pass Condition

#### Scenario 1

Consider a scenario where you wish to make an image eligible for deployment only if its tag version is greater than `v0.0.7`

The CEL Expression should be `containerImageTag > "v0.0.7"`
Expand All @@ -102,6 +105,25 @@ Clicking the filter icon at the top-left shows the filter condition(s) applied t

![Figure 12b: Conditions Applied](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/global-configurations/filters/conditions-applied-1.jpg)

#### Scenario 2

Consider another scenario where you wish to make images eligible for deployment only if the application's git branch starts with the word `hotfix` and also if its repo URL matches your specified condition.

**CEL Expression**:

`gitCommitDetails.filter(gitCommitDetail, gitCommitDetail.startsWith('https://github.com/devtron-labs')).map(repo, gitCommitDetails[repo].branch).exists_one(branch, branch.startsWith('hotfix-'))`

where, `https://github.com/devtron-labs` is a portion of the repo URL <br />
and `hotfix-` is for finding the branch name (say *hotfix-sept-2024*)

Alternatively, if you have a fixed branch (say *hotfix-123*), you may write the following expression:

`'hotfix-123' in gitCommitDetails.filter(gitCommitDetail, gitCommitDetail.startsWith('https://github.com/devtron-labs')).map(repo, gitCommitDetails[repo].branch)`

**Walkthrough Video**:

{% embed url="https://www.youtube.com/watch?v=R8IbZhXhH-k" caption="Filter Condition Example" %}


### Fail Condition

Expand Down
Loading