We use declarative pipelines and have some custom steps we call in the very first stage that check for changes in specific files which should skip the build and mark it as NOT_BUILT.
We do this because some changes do not really require new builds like changes in changelogs, gitignore, etc.
Another skip function we have, skips builds in case they contain a specific commit message. These usually come from release plugins which generate version bump commits once a PR is merged to master. Without having the skip functionality we would end up with continuously triggered builds.
Both functions mark the build as NOT_BUILT.
Unfortunately such skipped builds are reported to Bitbucket as failed builds. When you configure your project to allow merges only if you have at least one green build than this will basically block you.
And once your PR ends up in master your merge will first be green but the following commits created by for example the Gradle release plugin will be marked as red.
To avoid this we can mark builds of state NOT_BUILT as successful in Bitbucket. Unfortunately there is no other state (SUCCESS, FAILURE, INPROGRESS) available in Bitbucket that we could use instead.