How not to execute whole job including 'post/always' section in declarative pipeline if lockable resource is locked?

Hello,
I’ve put resource lock as an option on pipeline level with “skipIfLocked: true”. Steps are skipped but ‘post/always’ section is executed. How not to execute whole job including ‘post/always’ section in declarative pipeline if lockable resource is locked?
Snippet:

pipeline {
    options {
        lock(resource: '***', skipIfLocked: true)
    }
    post {
        always {
            echo '***'
        }
    }
}

Thanks,
Sam

Well, ‘always’ does have a very specific meaning. That block always runs regardless of whether the pipeline succeeded or failed.

There is a large selection of conditions you can use in post as shown in Pipeline Syntax
Maybe one of them would be better suited to what you’re doing.

You could also consider putting post inside a stage so that the stage needs to run first.

Thank you for valuable reply. Maybe I could put lock outside of pipeline like this?
lock(resource: '***', skipIfLocked: true) { pipeline { post { always { echo '***' } } } }

Eventually, I’ve done ‘workflow specific’ solution: set variable in first step (it will be not set if pipeline is skipped because of lock) and check it in post.

Given that you showed that lock is an option of the pipeline, I don’t believe you can flip it outside the pipeline like that.