title: Get Jenkins build number via Groovy script?
body: <p>I have a Jenkins parameterized build called "deploy-job", and I use the Extensible Choice option set to System Groovy Choice Parameter. In the Groovy Script box, I have this</p>
  
  <pre><code>import hudson.model.*
  
  BUILD_JOB_NAME = "build-multi-branch-pipeline-job"
  
  def getJobs() {
      def hi = Hudson.instance
      return hi.getItems(Job)
  }
  
  def getBuildJob() {
      def buildJob = null
      def jobs = getJobs()
      (jobs).each { job -&gt;
          if (job.displayName == BUILD_JOB_NAME) {
              buildJob = job
          }
      }
      return buildJob
  }
  
  def getAllBuildNumbers(Job job) {
      def buildNumbers = []
      (job.getBuilds()).each { build -&gt;
          def status = build.getBuildStatusSummary().message
          if (status.contains("stable") || status.contains("normal")) {
            buildNumbers.add(build.BUILD_NUMBER.toString())
          }
      }
      return buildNumbers
  }
  
  def buildJob = getBuildJob()
  return getAllBuildNumbers(buildJob)
  </code></pre>
  
  <p>However, when I run my "deploy-job", I'm NOT seeing the build numbers of "multi-branch-pipeline-job" in the choice box when I run Build with parameters, it's jub blank!</p>
  
  <p>I suspect I'm not doing this call right?</p>
  
  <pre><code>buildNumbers.add(build.BUILD_NUMBER.toString())
  </code></pre>
  
  <p>What is the correct syntax in this case? Thanks!</p>