Not able to read Git Environment variables Jenkins using Groovy Jenkinsfile Not able to read Git Environment variables Jenkins using Groovy Jenkinsfile jenkins jenkins

Not able to read Git Environment variables Jenkins using Groovy Jenkinsfile


This won't work due to lack of double quotes, missing curly braces, and missing env.:

sh 'echo $BRANCH_NAME' 

This works as expected in a Jenkinsfile:

node {    sh "echo ${env.BRANCH_NAME}"}


So, anyone else who has stumbled onto this Stackoverflow issue should be aware that this is a bug with the current pipeline situation.

Lots of discussion here: https://issues.jenkins-ci.org/browse/JENKINS-35230

Essentially the plugin is not able to correctly add environment variables due to some incompatibilities with pipeline.


This is fixed in Git plugin 3.3.1

Version 3.3.1 (Jun 23, 2017)

  • Print first line of commit message in console log (JENKINS-38241)
  • Allow scm steps to return revision (JENKINS-26100)
  • Don't require crumb for POST to /git/notifyCommit even when CSRF is enabled (JENKINS-34350)
  • Fix credentials tracking null pointer exception in pipeline library use (JENKINS-44640)
  • Fix credentials tracking null pointer exception in git parameters use (JENKINS-44087)