'Jenkins declarative pipeline when condition not working

I have written a declarative pipeline using shared library and I am using when condition. Even though the condition is true, the stage is getting skipped. I am unable to figure out. Am I missing something? Below is my code:

Branch Name: hotfix-poc. My branch name satisfies the condition but it still skips.

// Approve DEV Deployment
            stage('Approve Dev Deployment') {
                agent none
                when {
                    anyOf {
                        expression {
                            return (env.GIT_BRANCH.equals('master') || env.GIT_BRANCH.startsWith('hotfix-'))
                        }
                    }
                }
                steps{
                    approveDeployment(hcEnv: 'dev')
                }
            }

Jenkins Build Logs:

[Pipeline] { (Approve Dev Deployment)
Stage "Approve Dev Deployment" skipped due to when conditional
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage

Jenkins version: 2.319.1
Pipeline plugin version: 2.6



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source