Get vars in Jenkins Pipeline In FreeStyle Project, I have lots of env vars, which are available from any part of Jenkins' job. I also used ghprb plugin to trigger that job against GH PRs, which added some extra env vars.

Later, that job became more complex, so I've decided to put it on Jenkins Pipeline. But now, the issue is, I can't retrieve those env vars in a pipeline, which were available before, in the Freestyle Project.

I'm a newbie in writing Jenkins Pipeline, that's why I decided to use declarative approach for that purpose (but I don't think it's root cause). So, my question is, how to retrieve env vars in Jenkins Pipeline, such as: ${BUILD_CAUSE}, ${ghprbTargetBranch}, ${ghprbActualCommitAuthorEmail}?
If you want to use environment variables with the ${VAR} syntax in the declarative pipeline, then you need to define those variables in the environment { } block.

for example:  

environment {
        DISABLE_AUTH = 'true'
        DB_ENGINE    = 'sqlite'
    }

    stages {
        stage('Build') {
            steps {
                echo "Database engine is ${DB_ENGINE}"
                echo "DISABLE_AUTH is ${DISABLE_AUTH}"
                sh 'printenv'
            }
        }
    }



If you want to use environment variables that come from other plugins etc, then you need to access them with the env.VAR syntax.  For example:

echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"