title: write a csv file on a jenkins slave using groovy
body: <p>I need to write a csv file from a large json file on a jenkins slave using groovy. Previously the method I used first was only ran on the 'Master' see below: </p>
  
  <pre><code>def file = new FilePath(channel, envVars['WORKSPACE'] + separator + 'FDCUtilities' + separator + 'GroovyTest' + separator + 'json.json')
  def outPutCSV = envVars['WORKSPACE'] + separator + 'FDCUtilities' + separator + 'GroovyTest' + separator + 'test.csv'
  
  def results = jsonSlurper.parseText(file.readToString())
  def FILE_HEADER = ['ID','TEST NAME','TOTALLINES', 'TOTAL COVERED', 'COVERED %']
  
  new File(outPutCSV).withWriter { fileWriter -&gt;
      csvFilePrinter = new CSVPrinter(fileWriter, CSVFormat.DEFAULT)
      csvFilePrinter.printRecord(FILE_HEADER)
      results.each{
          csvFilePrinter.printRecord([it.id, it.name, it.totalLines, it.totalCovered, it.coveredPercent])
      }
  }
  </code></pre>
  
  <p>Seeing as we can no longer use file and must use 'FilePath' I cannot figure out for the life of me how to the previous csv writer with the new FilePath.  My thought is you just can't as I am having trouble finding documentation where you can either append a file with filepath or write csv's with it. My thought was just to make a string value and assigning csv to the write file, however, I cannot get it to seem to look right or work properly.</p>
  
  <p>My current code: </p>
  
  <pre><code>def jsonSlurper = new JsonSlurper()
  
  // access the files on the current workspace regardless slave or master
  def file = new FilePath(channel, envVars['WORKSPACE'] + separator + 'FDCUtilities' + separator + 'GroovyTest' + separator + 'json.json')
  def outPutCSV = new FilePath(channel, envVars['WORKSPACE'] + separator + 'FDCUtilities' + separator + 'GroovyTest' + separator + 'test.csv')
  
  def results = jsonSlurper.parseText(file.readToString())
  
      test = "ID,TEST NAME,TOTAL LINES,TOTAL COVERED,COVERED %"
      results.each {
          test = test.concat(it.id, it.name, it.totalLines, it.totalCovered, it.coveredPercent, "\n")
      }
  
      outPutCSV.write(test ,null)
  </code></pre>
  
  <p>I am still learning groovy and jenkins working together so any help would be greatly appreciated!</p>