title: Write Jenkins build result to JSON
body: <p>I am trying to create JSON output of a Jenkins build using Groovy's JsonBuilder and the Groovy PostBuild Plugin.  Everything seems to be working except the build result.  Instead of giving me the actual result of the build in the JSON output it is giving me an array of all possible results (i.e. SUCCESS, UNSTABLE, FAILURE, etc.).  If I just print out the result to the console it prints just the actual result.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>import groovy.json.*
  
  def result = manager.build.result
  manager.listener.logger.println result       // Prints just the build result
  
  def json = new groovy.json.JsonBuilder()
  def root = json.build {
      build_number manager.build.number
      build_timestamp manager.build.timestamp
      build_duration manager.build.duration 
      build_url manager.build.url
      build_project_name manager.build.project.name
      build_culprits manager.build.culprits
      build_result result                  // Prints an array of all possible results
      build_result manager.build.result    // Also prints an array of all possible results
  }
  
  manager.listener.logger.println "...and the status is ${result}"     // Prints just the   build result
  manager.listener.logger.println JsonOutput.prettyPrint(json.toString())
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>UNSTABLE
  ...and the status is UNSTABLE
  {
      "build": {
          "build_number": 85,
          "build_timestamp": "2014-01-14T13:26:06+0000",
          "build_duration": 0,
          "build_url": "job/JSON_Test/85/",
          "build_project_name": "JSON_Test",
          "build_culprits": [
  
          ],
          "build_result": {
              "names": [
                  "SUCCESS",
                  "UNSTABLE",
                  "FAILURE",
                  "NOT_BUILT",
                  "ABORTED"
              ],
              "completeBuild": true
          }
      }
  }
  </code></pre>
  
  <p>I have tried various different syntax combinations for the variable result such as $result, ${result} and ${result} in the json.build block, but all result in compile errors.</p>