diff --git a/src/main/java/org/jenkinsci/plugins/environmentdashboard/DashboardBuilder.java b/src/main/java/org/jenkinsci/plugins/environmentdashboard/DashboardBuilder.java index e79710b..f16068c 100644 --- a/src/main/java/org/jenkinsci/plugins/environmentdashboard/DashboardBuilder.java +++ b/src/main/java/org/jenkinsci/plugins/environmentdashboard/DashboardBuilder.java @@ -140,7 +140,14 @@ public void tearDown(Run build, FilePath workspace, Launcher launcher, Tas String passedBuildJob = build.getEnvironment(listener).expand(buildJob); String passedPackageName = build.getEnvironment(listener).expand(packageName); String doDeploy = build.getEnvironment(listener).expand("$UPDATE_ENV_DASH"); - List passedColumnData = Collections.emptyList(); + // Pass column data to post-build runQuery + List passedColumnData = new ArrayList(); + if (addColumns) { + for (ListItem item : data) { + passedColumnData.add(new ListItem(build.getEnvironment(listener).expand(item.columnName), + build.getEnvironment(listener).expand(item.contents))); + } + } String returnComment = null; if (passedPackageName == null) { @@ -211,7 +218,7 @@ private String writeToDB(Run build, TaskListener listener, String envName, columns = columns + ", " + item.columnName; contents = contents + "', '" + item.contents; try { - stat.execute("ALTER TABLE env_dashboard ADD IF NOT EXISTS " + item.columnName + " VARCHAR;"); + stat.execute("ALTER TABLE env_dashboard ADD COLUMN IF NOT EXISTS " + item.columnName + " VARCHAR;"); } catch (SQLException e) { returnComment = "WARN: Could not alter table env_dashboard to add column " + item.columnName + "."; return returnComment; @@ -236,8 +243,7 @@ private String writeToDB(Run build, TaskListener listener, String envName, buildJobUrl = ""; } else { buildJobUrl = "job/" + buildJob + "/" + currentBuildNum; - } - + } String runQuery = null; if (runTime.equals("PRE")) { runQuery = "INSERT INTO env_dashboard (envComp, jobUrl, buildNum, buildStatus, envName, compName, created_at, buildJobUrl, packageName" @@ -246,9 +252,15 @@ private String writeToDB(Run build, TaskListener listener, String envName, + buildJobUrl + "' , '" + packageName + contents + "');"; } else { if (runTime.equals("POST")) { - runQuery = "UPDATE env_dashboard SET buildStatus = '" + currentBuildResult - + "', created_at = current_timestamp WHERE envComp = '" + indexValueofTable + "' AND joburl = '" - + currentBuildUrl + "';"; + // Updates build no. and additional columns also in post-build update + String updateColumns = ""; + for (ListItem item : passedColumnData) { + updateColumns += "," + item.columnName + "=" + "'" + item.contents + "'"; + } + runQuery = "UPDATE env_dashboard SET buildNum = '" + currentBuildNum + "', buildStatus = '" + currentBuildResult + + "', created_at = current_timestamp " + updateColumns + " WHERE envComp = '" + indexValueofTable + "' AND joburl = '" + + currentBuildUrl + "';"; + listener.getLogger().println("DEBUG: Final Post-Build runQuery:" + runQuery); } else { if (runTime.equals("NODEPLOY")) { runQuery = "DELETE FROM env_dashboard where envComp = '" + indexValueofTable + "' AND joburl = '"