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 2 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,15 @@ 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();
//List<ListItem> passedColumnData = Collections.emptyList();
mvignesh12 marked this conversation as resolved.
Show resolved Hide resolved
// 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 @@ -172,7 +180,7 @@ public void tearDown(Run<?, ?> build, FilePath workspace, Launcher launcher, Tas
context.setDisposer(new TearDownImpl());
}

@SuppressWarnings("rawtypes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove this suppress?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it back. I removed it during code modifications.


private String writeToDB(Run<?, ?> build, TaskListener listener, String envName, String compName,
String currentBuildNum, String runTime, String buildJob, Integer numberOfDays, String packageName,
List<ListItem> passedColumnData) {
Expand Down Expand Up @@ -211,12 +219,12 @@ 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;
}
}
}
mvignesh12 marked this conversation as resolved.
Show resolved Hide resolved
String indexValueofTable = envName + '=' + compName;
String currentBuildResult = "UNKNOWN";
if (build.getResult() == null && runTime.equals("PRE")) {
Expand All @@ -236,19 +244,24 @@ 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"
+ columns + ") VALUES( '" + indexValueofTable + "', '" + currentBuildUrl + "', '" + currentBuildNum
+ "', '" + currentBuildResult + "', '" + envName + "', '" + compName + "' , + current_timestamp, '"
+ buildJobUrl + "' , '" + packageName + contents + "');";
+ buildJobUrl + "' , '" + packageName + contents + "');";
mvignesh12 marked this conversation as resolved.
Show resolved Hide resolved
} else {
if (runTime.equals("POST")) {
runQuery = "UPDATE env_dashboard SET buildStatus = '" + currentBuildResult
+ "', created_at = current_timestamp WHERE envComp = '" + indexValueofTable + "' AND joburl = '"
+ currentBuildUrl + "';";
if (runTime.equals("POST")) {
// 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 All @@ -260,7 +273,7 @@ private String writeToDB(Run<?, ?> build, TaskListener listener, String envName,
stat.execute(runQuery);
} catch (SQLException e) {
returnComment = "Error running query " + runQuery + ".";
return returnComment;
return returnComment + e;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail, e is not a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it to print the exact exception which I was getting during debugging. Removed it now.

}
if (numberOfDays > 0) {
runQuery = "DELETE FROM env_dashboard where created_at <= current_timestamp - " + numberOfDays;
Expand Down