Skip to content

Commit

Permalink
Merge pull request #164 from mvignesh12/fix/BuildUserVarsPlugin
Browse files Browse the repository at this point in the history
Fix/build user vars plugin
  • Loading branch information
willwh authored Feb 18, 2020
2 parents f8843c4 + 5a4f588 commit a2b8be7
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListItem> passedColumnData = Collections.emptyList();
// Pass column data to post-build runQuery
List<ListItem> passedColumnData = new ArrayList<ListItem>();
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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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"
Expand All @@ -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 = '"
Expand Down

0 comments on commit a2b8be7

Please sign in to comment.