Condition Filter not working

Hello Team,

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

BUILDKITE_MESSAGE="Merge pull request #114 from vth90x/bk_automated_from_spconfig-278
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
1 Like

Hey @sukurams!

I’m not seeing anything rare in your solution :thinking:. 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!

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

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"

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

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

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

The Build message I just noticed

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

Automated PR - Testing export and import"
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/

@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

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.

@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

@bmc - 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.

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

Automated PR - Testing export and import"

Hey! Can you send a particular build example to support@buildkite.com so we can better check this? Thanks!