title: groovy.lang.MissingPropertyException: No such property: Jenkins for class: hudson
body: <p>I am trying to run a groovy script in Jenkins slave node to retrieve child jobs from a folder in Jenkins slave node. Here is the groovy script I tried:</p>
  
  <p>I tried some SO answers and found <a href="https://stackoverflow.com/questions/47064135/groovy-lang-missingpropertyexception-no-such-property-jenkins-for-class-groov">groovy.lang.MissingPropertyException: No such property: jenkins for class: groovy.lang.Binding</a></p>
  
  <p>But this doesn't solve my problem.</p>
  
  <p>Please find the code that I tried:</p>
  
  <pre><code>import groovy.json.JsonSlurper
  import groovy.json.JsonBuilder
  import jenkins.model.*
  
  static main(args){
  
      def childJobFolder = "childJob"
      def childJobNameList = []
  
      def env = System.getenv()
  
      // Setting the environment properties to variables.
      def jenkinsUsername = env.UAT_JENKINS_MY_USER
      def jenkinsPassword = env.UAT_JENKINS_MY_PASS
  
      def jsonSlurper = new JsonSlurper()
  
      // Getting the child job names from "childJob" folder
      Jenkins.instance.getItemByFullName(childJobFolder).allJobs.each{
          def childJobName = it.name.toString()
          if(childJobName.startsWith("job-")){
              childJobNameList.add(childJobName)
          }
      }
  
      println "\n" + "Child Jobs Available: " + childJobNameList + "\n"
  
  }
  </code></pre>
  
  <p>Here is what I got in the console:</p>
  
  <blockquote>
    <p>Caught: groovy.lang.MissingPropertyException: No such property: Jenkins for class: hudson3067346520259876246
    groovy.lang.MissingPropertyException: No such property: Jenkins for class: hudson3067346520259876246
        at hudson3067346520259876246.run(hudson3067346520259876246.groovy:17)
    Build step 'Execute Groovy script' marked build as failure</p>
  </blockquote>
  
  <p>Can someone help me to fix this error? Thanks in advance!</p>