title: How to get the current build's node name in jenkins using groovy
body: <p>I have a pipeline job running in Jenkins and I want to know the name of the node it's running on. Is there a way to get the node name from within the job's Groovy script?</p>
  
  <p>I have tried the below code:</p>
  
  <pre><code>print currentBuild.getBuiltOn().getNodeName()
  </code></pre>
  
  <p>the error is:</p>
  
  <pre><code>org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified method org.jenkinsci.plugins.workflow.job.WorkflowRun getBuiltOn
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>def build = currentBuild.build()
  print build.getExecutor().getOwner().getNode().getNodeName()
  </code></pre>
  
  <p>but the result is ''.</p>