Can I check if Environment variable exist or not in Jenkinsfile : <p>I am running Multibranch pipeline for my project.</p>

<p>The behaviour of Jenkinsfile should change according to the trigger.
There are two events that triggeres the pipeline 1. Push event 2. Pull Request.</p>

<p>I am trying to check Environment variable 'CHANGE_ID' ('CHANGE_ID' will be available for Pull Request only).<a href="https://jenkins.io/doc/book/pipeline/multibranch/#additional-environment-variables" rel="noreferrer">Reference</a> .</p>

<p>So if pipeline is triggred by Push event and If check the 'CHANGE_ID' variable it throws exception (code works fine if pipeline gets triggered by Pull Request).</p>

<p><strong>Code:</strong></p>

<pre><code>stage('groovyTest'){
    node('mynode1') {
        if (CHANGE_ID!=NULL){
            echo "This is Pull request"
        }else{
            echo "This is Push request"
        }
    }
}
</code></pre>

<p><strong>Error:</strong></p>

<pre><code>groovy.lang.MissingPropertyException: No such property: CHANGE_ID for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)
    at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:241)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:238)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
    at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:221)
    at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:28)
    at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
    at WorkflowScript.run(WorkflowScript:5)
    at ___cps.transform___(Native Method)
</code></pre>

<p>How can I check the 'CHANGE_ID' variable exist or not in Jenkinsfile?</p>
