Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

build.getErrorMessage() allways null #4590

Laba42 ·

I save important build data (status, duration, starter, project name, etc.) in a database table in the AdvancedSetting in the Post-Build Script section.
Now I want to extend the table with the error message why the build was canceled.

def errorMsg = build.getErrorMessage()

But no matter with which error message the build is canceled, the variable errorMsg is always null.

If an error is present then
build.hasErrors() = true
and
build.getStatus() = FAILED
only
build.getErrorMessage() = null

What am I doing wrong?

QB Version: 13.0.22, 2023-06-05

  • solved #4
  • replies 3
  • views 71
  • stars 0
robinshen ADMIN ·

I save important build data (status, duration, starter, project name, etc.) in a database table in the AdvancedSetting in the Post-Build Script section.

How are you doing that? These info is expected to be populated by QB automatically, and should not be changed via script.

Laba42 ·

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

robinshen ADMIN ·

I see. build.errorMessage contains error message not associated with certain steps. You also need to check error messages for each step like below:

groovy: 
for (entry in build.stepRuntimes) { 
  if (entry.value.errorMessage != null) 
    logger.info(entry.key + ":" + entry.value.errorMessage); 
}