We save the data in an external Oracle database table in order to create reports such as the change in construction duration or how many buildings we have per day/week/month, etc.
We do this with the following code in the Post Buils Script field in the Advanced Settings
def version = vars.get("VersionNumber").getValue()
def famVer = vars.get("FamVersion").getValue()
def project = vars.get("ProjectName").getValue()
def cbDoku = vars.get("CBCreateDocu").getValue()
def cbJunit = vars.get("CBRunTest").getValue()
def cbCrypt = vars.get("CBEncrypt").getValue()
def depot = vars.get("SourceDepot").getValue()
def nodeAdress = build.getMasterStep().getNodeAddress()
nodeAdress = nodeAdress.substring(0, nodeAdress.indexOf(":"))
def nodeName = nodeAdress.replace("QB64-","")
def bob = "Scheduler"
if (!request.isScheduled())
bob = user.fullName
def lableName = vars.get("LabelOrChangeList").getValue()
def branchName = configuration.parent.name
def parentBranch= configuration.parent.parent.name
def configName = configuration.name
def configPath = configuration.getPathName()
configPath = configPath.replace(configName ,"")
def duration = build.getDuration()
def status = build.getStatus().toString()
def buildID = build.getId()
def successful = 0
def startDate = build.getBeginDate()
def dbStartDate = "to_date('" + startDate.format("dd.MM.yyyy HH:mm:ss") +"','" + "dd.mm.yyyy hh24:mi:ss" + "') "
def errorMsg = build.getErrorMessage()
if (status.equals("SUCCESSFUL")){
successful = 1
}
// Die Groessed des Publish ud ARtifcats Verzeichnisses
def publishDir = new File (build.publishDir.getAbsolutePath() )
def artifcatDir = new File (build.artifactsDir.getAbsolutePath())
def pubSize = 0
def artSize = 0
if (publishDir.exists() ){
pubSize = publishDir.directorySize()
if (artifcatDir.exists() ){
artSize = artifcatDir.directorySize()
}
}
def dbConn = vars.getValue("KMDBConnection")
def sql = Sql.newInstance(dbConn, "user", "password", "oracle.jdbc.driver.OracleDriver");
Context.getLogger().debug(dbConn + " ,'km','km','oracle.jdbc.driver.OracleDriver'");
def insert = "INSERT INTO KPI (BUILD_ID, BRANCH, CONFIG_NAME, PROJECT,VERSION,DURATION, OK, DATUM, DOKU, JUNIT, LABLE, CRYPT, BUILDER, DEPOT, QBNODE, DATABASE,PUBSIZE,ARTSIZE,STARTDATUM, QB_CONFIG_ID, PATH , ERROR) values " +
"( " + buildID + ", '" + branchName + "','" + configName + "','" + project + "','" + version + "'," + duration + "," + successful +
", sysdate , '" + cbDoku + "','" + cbJunit + "','" + lableName + "','" + cbCrypt + "','" + bob + "','" + depot + "','" + nodeName + "','" + dataBase + "', " + pubSize + ", " + artSize + ", " + dbStartDate +
", " + confId + " ,'" + configPath + "','" + errorMsg + "')"
Context.getLogger().debug("Insert=" +insert )
sql.connection.autoCommit = false
try {
sql.execute (insert)
sql.commit()
logger.info("Insert = " + insert + " war erfolgreich" )
}
catch(Exception ex) {
sql.rollback()
logger.info("Insert = " + insert + " konnte nicht ausgeführt werden")
}
and now I wanted to add the errorMsg to our table, but this does not work