Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import hudson.model.*
- import java.math.*
- def apiKey = "aSecret"
- def buildId = System.getenv("BUILD_ID")
- def buildNo = System.getenv("BUILD_NUMBER")
- def jobName = System.getenv("JOB_NAME")
- jobName.replace(".","-")
- def nodeName = System.getenv("NODE_NAME")
- def (startDate, startTime) = buildId.tokenize("_")
- def (YY, MM, DD) = startDate.tokenize("-")
- def (hh, mm, ss) = startTime.tokenize("-")
- MathContext mc = new MathContext(200);
- Date startDateTime = new GregorianCalendar(YY.toInteger(), MM.toInteger() - 1, DD.toInteger(), hh.toInteger(), mm.toInteger(), ss.toInteger()).time
- Date end = new Date()
- long diffMillis = end.getTime() - startDateTime.getTime()
- long second = (diffMillis / 1000).remainder(60, mc);
- long minute = (diffMillis / (1000 * 60)).remainder(60, mc);
- long hour = (diffMillis / (1000 * 60 * 60)).remainder(24, mc);
- String buildDuration = String.format("%02d:%02d:%02d", hour, minute, second);
- String metric = String.format("%s.jenkins.%s.%s.%s.duration %s", apiKey, nodeName, jobName, buildNo, buildDuration)
- println "echo "+ metric +" | nc carbon.hostedgraphite.com 2003"
- "echo "+ metric +" | nc carbon.hostedgraphite.com 2003".execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement