# Condition Filter not working

**URL:** <https://forum.buildkite.community/t/condition-filter-not-working/2357>\
**Category:** Pipelines\
**Created:** [November 8, 2022, 8:36pm UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357 "2022-11-08T20:36:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 8, 2022, 8:36pm UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/1 "2022-11-08T20:36:51Z")

</div>

Hello Team,

I have following pipeline to check the condition before trigger but looks like not working fine. Can someone share thoughts ?

```auto
BUILDKITE_MESSAGE="Merge pull request #114 from vth90x/bk_automated_from_spconfig-278

```

```auto
agents:
      queue: docker
steps:
  - label: 'Prepare BuildKite Pipeline file'
    commands:
      - pwsh .buildkite/scripts/module-yaml.ps1
      - pwsh .buildkite/scripts/functions.ps1
      - pwsh .buildkite/scripts/preparevaultpipeline.ps1
      - buildkite-agent pipeline upload .buildkite/integratevault.yml
    if: |
      // Don't when the message contains "MESSAGE_TO_IGNORE_BUILD"
      // Don't when the message contains bk_automated_from_spconfig
      build.message !~ /MESSAGE_TO_IGNORE_BUILD/ &&
        build.message !~ /bk_automated_from_spconfig/
  - wait

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [November 8, 2022, 9:06pm UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/2 "2022-11-08T21:06:00Z")

</div>

Hey @sukurams!

I’m not seeing anything rare in your solution 🤔. In this particular case, are you saying that it’s not running that command? Can you check the value of `BUILDKITE_MESSAGE` in the `Environment` tab and confirm that is the one you are expecting?

Best!

---

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 9, 2022, 3:03am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/3 "2022-11-09T03:03:16Z")

</div>

Thank you for your message @paula. The issue is , the filter is not stoping the build when build message is ```  
BUILDKITE\_MESSAGE="Merge pull request #114 from xxxx/bk\_automated\_from\_spconfig-278

````auto
I expecting the if condition execute and stop the build. 

The first if loop workingZ(build.message !~ /MESSAGE_TO_IGNORE_BUILD/) as expected when error message as ```
BUILDKITE_MESSAGE="MESSAGE_TO_IGNORE_BUILD"

````

---

<div class="post-metadata">

**Author:** ![benmc](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/benmc/32/1159_2.png) [@benmc](https://forum.buildkite.community/u/benmc)\
**Post date:** [November 9, 2022, 3:06am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/4 "2022-11-09T03:06:45Z")

</div>

Hi @sukurams!

You’re using `&&` so both conditions need to be met, if you want one or the other you should use `||` as your logic operator, which represents `OR`.

Cheers,

Ben

---

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 9, 2022, 3:17am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/5 "2022-11-09T03:17:01Z")

</div>

Thank you @benmc. I have tried both before. Can you please confirm the condition looks good to check contain string from build message ?

---

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 9, 2022, 3:31am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/6 "2022-11-09T03:31:08Z")

</div>

As I mentioned above, I have tested with below changes.

The Build message I just noticed

```auto
BUILDKITE_MESSAGE="Merge pull request #114 from xxxx/bk_automated_from_spconfig-278

Automated PR - Testing export and import"

```

```auto
if: |
      // Don't when the message contains "MESSAGE_TO_IGNORE_BUILD"
      // Don't when branch name bk_automated_from_spconfig
      build.message !~ /MESSAGE_TO_IGNORE_BUILD/ ||
        build.message !~ /bk_automated_from_spconfig/

```

---

<div class="post-metadata">

**Author:** ![benmc](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/benmc/32/1159_2.png) [@benmc](https://forum.buildkite.community/u/benmc)\
**Post date:** [November 9, 2022, 3:35am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/7 "2022-11-09T03:35:56Z")

</div>

@sukurams

Firstly, it is `&&`, apologies, I’m always wrong with logical operators.

The only time I’ve been able to make this set up fail is by using the wrong case, for example `message_to_ignore_build` rather than `MESSAGE_TO_IGNORE_BUILD`.

Ben

---

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 9, 2022, 3:38am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/8 "2022-11-09T03:38:31Z")

</div>

I think build.message !~ /MESSAGE\_TO\_IGNORE\_BUILD/ logic working as expected but build.message !~ /bk\_automated\_from\_spconfig/ not working since build message having spaces. is there any way we can fix it ?

Or is there any way I can setup the build message / any other environment variable to check.

---

<div class="post-metadata">

**Author:** ![benmc](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/benmc/32/1159_2.png) [@benmc](https://forum.buildkite.community/u/benmc)\
**Post date:** [November 9, 2022, 4:30am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/9 "2022-11-09T04:30:47Z")

</div>

@sukurams I’ve been able to locate the relevant build and the step doesn’t have the logic to not build on `/bk_automated_from_spconfig/`

![Screenshot 2022-11-09 at 3.30.35 pm](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/f/f5ba6a9011f32294c2c221de99be1ea8a5d95027.png)

---

<div class="post-metadata">

**Author:** ![sukurams](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@sukurams](https://forum.buildkite.community/u/sukurams)\
**Post date:** [November 9, 2022, 12:27pm UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/10 "2022-11-09T12:27:32Z")

</div>

@benmc - The background, I have to check the both build message and avoid to execute the build. all I looking with spaces in build message how to validate the build message contain.

Expected Build Message when Auto PR creation and merge the commit to main branch.

```auto
 BUILDKITE_MESSAGE="Merge pull request #114 from xxxx/bk_automated_from_spconfig-278

Automated PR - Testing export and import"

```

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [November 9, 2022, 11:10pm UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/11 "2022-11-09T23:10:14Z")

</div>

Hey! Can you send a particular build example to [support@buildkite.com](mailto:support@buildkite.com) so we can better check this? Thanks!

---

<div class="post-metadata">

**Author:** ![paula](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/paula/32/954_2.png) [@paula](https://forum.buildkite.community/u/paula)\
**Post date:** [August 29, 2023, 5:39am UTC](https://forum.buildkite.community/t/condition-filter-not-working/2357/12 "2023-08-29T05:39:33Z")

</div>


