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
if you really want to loop over the env list just do:
def envs = sh(returnStdout: true, script: 'env').split('\n') envs.each { name -> println "Name: $name" }