Given a jenkins 2.1 build pipeline, jenkins injects a env variable into the node{}. For example, BRANCH_NAME can be accessed with
env
node{}
BRANCH_NAME
Why all this complicatedness?
sh 'env'
does what you need (under *nix)