I currently have a Jenkins job which is triggered from GitHub.
How do I checkout the branch which triggered the Jenkins job using Jenkins Pipelines?
I've been trying to use something like:
checkout([$class: 'GitSCM', 
branches: [[name: env.BRANCH_NAME]], 
doGenerateSubmoduleConfigurations: 
false, extensions: [[$class: 'RelativeTargetDirectory', 
relativeTargetDir: 'mytargetdirectory']], userRemoteConfigs: [[credentialsId: 'id-123', 
url: 'https://github.com/my/repourl']]])
In the example above, env.BRANCH_NAME is evaluated as null.
However, I'm not sure what the value in branches should be to checkout the branch which triggered the job.
The payload from GitHub contains:
  "ref": "refs/heads/branchname",
Is there a way to extract this information from the payload to get the branchname?
Any help on this would be greatly appreciated!