Advertisement
Guest User

Untitled

a guest
Sep 29th, 2017
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. import hudson.model.*
  3. import java.math.*
  4.  
  5. def apiKey = "aSecret"
  6. def buildId = System.getenv("BUILD_ID")
  7. def buildNo = System.getenv("BUILD_NUMBER")
  8. def jobName = System.getenv("JOB_NAME")
  9. jobName.replace(".","-")
  10. def nodeName = System.getenv("NODE_NAME")
  11. def (startDate, startTime) = buildId.tokenize("_")
  12. def (YY, MM, DD) = startDate.tokenize("-")
  13. def (hh, mm, ss) = startTime.tokenize("-")
  14.  
  15. MathContext mc = new MathContext(200);
  16.  
  17. Date startDateTime = new GregorianCalendar(YY.toInteger(), MM.toInteger() - 1, DD.toInteger(), hh.toInteger(), mm.toInteger(), ss.toInteger()).time
  18. Date end = new Date()
  19. long diffMillis = end.getTime() - startDateTime.getTime()
  20.  
  21. long second = (diffMillis / 1000).remainder(60, mc);
  22. long minute = (diffMillis / (1000 * 60)).remainder(60, mc);
  23. long hour = (diffMillis / (1000 * 60 * 60)).remainder(24, mc);
  24.  
  25. String buildDuration = String.format("%02d:%02d:%02d", hour, minute, second);
  26.  
  27. String metric = String.format("%s.jenkins.%s.%s.%s.duration %s", apiKey, nodeName, jobName, buildNo, buildDuration)
  28. println "echo "+ metric +" | nc carbon.hostedgraphite.com 2003"
  29. "echo "+ metric +" | nc carbon.hostedgraphite.com 2003".execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement