Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/build user vars plugin #164

Merged
merged 3 commits into from
Feb 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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