'How to resolve "groovy.lang.MissingPropertyException" in groovy?

I am new to groovy. I am writing a shared library for Jenkins pipeline. I am facing this groovy.lang.MissingPropertyException exception. Below is my code:

    def call(Map config = [:]) {
    
            pipeline {
                defaults = [
                        'pipelineStrategy'          : 'deployOnly',
                        'buildSystem'               : 'maven'
                ] + config
        
                environment {
                    BRANCH_NAME = "${GIT_BRANCH.split("/")[1]}"
                }
                boolean autoDeploy = false;
                if (BRANCH_NAME.equals('master') || BRANCH_NAME.startsWith('hotfix-')){
                    autoDeploy = true;
                }
        }
}

Below are my Jenkins build logs:

[Pipeline] Start of Pipeline
[Pipeline] End of Pipeline
hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: BRANCH_NAME for class: pipelineStrategy
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
    at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at pipelineStrategy.call(pipelineStrategy.groovy:21)


Sources

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

Source: Stack Overflow

Solution Source