Is there a way to specifey a "NOT MATCHES" filter?

Issue #21 resolved
Christian Schmitt created an issue

Hello, currently the documentation about filters is really limited. Is there a way to specify a "not matches branch" filter? Currently we don't want builds on the master branch. Since that branch will be built every evening. is that possible?

Or could you just extend the documentation?

Comments (3)

  1. Alexander Renteln

    Hi Christian,

    thanks for the feedback - I will try to add some more examples to the documentation.

    To answer your question: You can specify any regular expression and if it matches, it will not be filtered out. So you simply have to negate your regex.

    Here is also some code, if you're interested further. From https://bitbucket.org/aeffle/stash-http-get-post-receive-hook/src/23a667a4883a44850917f15ccd9a1909d8f600f0/src/main/java/de/aeffle/stash/plugin/hook/helper/ContextFilter.java?at=master&fileviewer=file-view-default

        /*
         * Check Filter will be true if:
         *  - the regex in the filter matches the data
         *  - the filter is empty
         *  - the regex is invalid (ignore errors)
         */
        private boolean checkIfFilterMatches(String data, String filter) {
            if (filter.isEmpty()) {
                return true;
            }
    
            try {
                return data.matches(filter);
            } catch (PatternSyntaxException e) {
                return true;
            }
        }
    

    You can check regex with commandline tools like grep or simply online e.g. here: https://regex101.com/

    Cheers, Alex

  2. Log in to comment