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

Feature/immutable #45

Merged
merged 3 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ effect:
2. [Build timeout plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build-timeout+Plugin)
3. [Timestamper plugin](https://wiki.jenkins-ci.org/display/JENKINS/Timestamper)
4. [ANSI color plugin](https://wiki.jenkins-ci.org/display/JENKINS/AnsiColor+Plugin)
5. [Slack plugin](https://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin) (required for slack notifications, version >= 2.0.1)

# USER GUIDE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void setRepositoryConfigurationForRepository(Repository repo,
verifyBranchRegex, verifyBuildCommand, false,
"N/A", publishBranchRegex, publishBuildCommand, false, "N/A", prebuildCommand, null, rebuildOnUpdate,
false, "N/A", rebuildOnUpdate, null, null, new EmailSettings(), false, false, false, false,
new BuildTimeoutSettings());
new BuildTimeoutSettings(), new SlackSettings());
}

/* (non-Javadoc)
Expand Down Expand Up @@ -274,13 +274,16 @@ public void setRepositoryConfigurationForRepositoryFromRequest(Repository repo,

Boolean timestampJobOutputEnabled = getBoolean(req, "isTimestampJobOutputEnabled");
Boolean ansiColorJobOutputEnabled = getBoolean(req, "isAnsiColorJobOutputEnabled");

BuildTimeoutSettings buildTimeoutSettings = getBuildTimeoutSettings(req);

SlackSettings slackSettings = getSlackSettings(req);

setRepositoryConfigurationForRepository(repo, ciEnabled, verifyBranchRegex, verifyBuildCommand, isVerifyPinned,
verifyLabel, publishBranchRegex, publishBuildCommand, isPublishPinned, publishLabel, prebuildCommand,
jenkinsServerName, rebuildOnUpdate, junitEnabled, junitPath, artifactsEnabled, artifactsPath,
maxVerifyChain, emailSettings, strictVerifyMode, preserveJenkinsJobConfig,
timestampJobOutputEnabled, ansiColorJobOutputEnabled, buildTimeoutSettings);
timestampJobOutputEnabled, ansiColorJobOutputEnabled, buildTimeoutSettings, slackSettings);
RepositoryConfiguration rc = getRepositoryConfigurationForRepository(repo);
setJobTypeStatusMapping(rc, JobType.VERIFY_COMMIT, getBoolean(req, "verificationEnabled"));
setJobTypeStatusMapping(rc, JobType.VERIFY_PR, getBoolean(req, "verifyPREnabled"));
Expand Down Expand Up @@ -328,6 +331,32 @@ private BuildTimeoutSettings getBuildTimeoutSettings(HttpServletRequest req) {
return new BuildTimeoutSettings(buildTimeoutEnabled, buildTimeout);
}

private SlackSettings getSlackSettings(HttpServletRequest req) {
Boolean slackEnabled = getBoolean(req, "slackEnabled");
String slackTeamDomain = req.getParameter("slackTeamDomain");
String slackAuthToken = req.getParameter("slackAuthToken");
String slackBuildServerUrl = req.getParameter("slackBuildServerUrl");
String slackRoom = req.getParameter("slackRoom");
String slackCommitInfoChoice = req.getParameter("slackCommitInfoChoice");
String slackCustomMessage = req.getParameter("slackCustomMessage");
Boolean slackStartNotification = getBoolean(req, "slackStartNotification");
Boolean slackNotifySuccess = getBoolean(req, "slackNotifySuccess");
Boolean slackNotifyAborted = getBoolean(req, "slackNotifyAborted");
Boolean slackNotifyNotBuilt = getBoolean(req, "slackNotifyNotBuilt");
Boolean slackNotifyUnstable = getBoolean(req, "slackNotifyUnstable");
Boolean slackNotifyFailure = getBoolean(req, "slackNotifyFailure");
Boolean slackNotifyBackToNormal = getBoolean(req, "slackNotifyBackToNormal");
Boolean slackNotifyRepeatedFailure = getBoolean(req, "slackNotifyRepeatedFailure");
Boolean slackIncludeTestSummary = getBoolean(req, "slackIncludeTestSummary");
Boolean slackIncludeCustomMessage = getBoolean(req, "slackIncludeCustomMessage");
return new SlackSettings(slackEnabled, slackTeamDomain, slackAuthToken,
slackBuildServerUrl, slackRoom, slackCommitInfoChoice,
slackCustomMessage, slackStartNotification, slackNotifySuccess,
slackNotifyAborted, slackNotifyNotBuilt, slackNotifyUnstable,
slackNotifyFailure, slackNotifyBackToNormal, slackNotifyRepeatedFailure,
slackIncludeTestSummary, slackIncludeCustomMessage);
}

private boolean getBoolean(HttpServletRequest req, String parameter) {
return (req.getParameter(parameter) == null) ? false : true;
}
Expand All @@ -346,7 +375,8 @@ private boolean getBoolean(HttpServletRequest req, String parameter) {
boolean artifactsEnabled, String artifactsPath, Integer maxVerifyChain, EmailSettings emailSettings,
boolean strictVerifyMode, Boolean preserveJenkinsJobConfig,
boolean timestampJobOutputEnabled, boolean ansiColorJobOutputEnabled,
BuildTimeoutSettings buildTimeoutSettings)
BuildTimeoutSettings buildTimeoutSettings,
SlackSettings slackSettings)
throws SQLException, IllegalArgumentException {
if (jenkinsServerName == null) {
jenkinsServerName = DEFAULT_JENKINS_SERVER_CONFIG_KEY;
Expand All @@ -360,9 +390,9 @@ private boolean getBoolean(HttpServletRequest req, String parameter) {
+ repo.getId());
RepositoryConfiguration rc = ao.create(
RepositoryConfiguration.class,
new DBParam("REPO_ID", repo.getId()), new DBParam(
"CI_ENABLED", isCiEnabled), new DBParam(
"VERIFY_BRANCH_REGEX", verifyBranchRegex),
new DBParam("REPO_ID", repo.getId()),
new DBParam("CI_ENABLED", isCiEnabled),
new DBParam("VERIFY_BRANCH_REGEX", verifyBranchRegex),
new DBParam("VERIFY_BUILD_COMMAND", verifyBuildCommand),
new DBParam("VERIFY_PINNED", isVerifyPinned),
new DBParam("VERIFY_LABEL", verifyLabel),
Expand All @@ -387,7 +417,24 @@ private boolean getBoolean(HttpServletRequest req, String parameter) {
new DBParam("TIMESTAMPS_ENABLED", timestampJobOutputEnabled),
new DBParam("ANSICOLOR_ENABLED", ansiColorJobOutputEnabled),
new DBParam("BUILD_TIMEOUT_ENABLED", buildTimeoutSettings.getBuildTimeoutEnabled()),
new DBParam("BUILD_TIMEOUT", buildTimeoutSettings.getBuildTimeout())
new DBParam("BUILD_TIMEOUT", buildTimeoutSettings.getBuildTimeout()),
new DBParam("SLACK_ENABLED", slackSettings.getSlackEnabled()),
new DBParam("SLACK_TEAM_DOMAIN", slackSettings.getSlackTeamDomain()),
new DBParam("SLACK_AUTH_TOKEN", slackSettings.getSlackAuthToken()),
new DBParam("SLACK_BUILD_SERVER_URL", slackSettings.getSlackBuildServerUrl()),
new DBParam("SLACK_ROOM", slackSettings.getSlackRoom()),
new DBParam("SLACK_COMMIT_INFO_CHOICE", slackSettings.getSlackCommitInfoChoice()),
new DBParam("SLACK_INCLUDE_CUSTOM_MESSAGE", slackSettings.getSlackIncludeCustomMessage()),
new DBParam("SLACK_CUSTOM_MESSAGE", slackSettings.getSlackCustomMessage()),
new DBParam("SLACK_START_NOTIFICATION", slackSettings.getSlackStartNotification()),
new DBParam("SLACK_NOTIFY_SUCCESS", slackSettings.getSlackNotifySuccess()),
new DBParam("SLACK_NOTIFY_ABORTED", slackSettings.getSlackNotifyAborted()),
new DBParam("SLACK_NOTIFY_NOT_BUILT", slackSettings.getSlackNotifyNotBuilt()),
new DBParam("SLACK_NOTIFY_UNSTABLE", slackSettings.getSlackNotifyUnstable()),
new DBParam("SLACK_NOTIFY_FAILURE", slackSettings.getSlackNotifyFailure()),
new DBParam("SLACK_NOTIFY_BACK_TO_NORMAL", slackSettings.getSlackNotifyBackToNormal()),
new DBParam("SLACK_NOTIFY_REPEATED_FAILURE", slackSettings.getSlackNotifyRepeatedFailure()),
new DBParam("SLACK_INCLUDE_TEST_SUMMARY", slackSettings.getSlackIncludeTestSummary())
);
if (maxVerifyChain != null) {
rc.setMaxVerifyChain(maxVerifyChain);
Expand Down Expand Up @@ -430,6 +477,23 @@ private boolean getBoolean(HttpServletRequest req, String parameter) {
foundRepo.setAnsiColorJobOutputEnabled(ansiColorJobOutputEnabled);
foundRepo.setBuildTimeoutEnabled(buildTimeoutSettings.getBuildTimeoutEnabled());
foundRepo.setBuildTimeout(buildTimeoutSettings.getBuildTimeout());
foundRepo.setSlackEnabled(slackSettings.getSlackEnabled());
foundRepo.setSlackTeamDomain(slackSettings.getSlackTeamDomain());
foundRepo.setSlackAuthToken(slackSettings.getSlackAuthToken());
foundRepo.setSlackBuildServerUrl(slackSettings.getSlackBuildServerUrl());
foundRepo.setSlackRoom(slackSettings.getSlackRoom());
foundRepo.setSlackCommitInfoChoice(slackSettings.getSlackCommitInfoChoice());
foundRepo.setSlackIncludeCustomMessage(slackSettings.getSlackIncludeCustomMessage());
foundRepo.setSlackCustomMessage(slackSettings.getSlackCustomMessage());
foundRepo.setSlackStartNotification(slackSettings.getSlackStartNotification());
foundRepo.setSlackNotifySuccess(slackSettings.getSlackNotifySuccess());
foundRepo.setSlackNotifyAborted(slackSettings.getSlackNotifyAborted());
foundRepo.setSlackNotifyNotBuilt(slackSettings.getSlackNotifyNotBuilt());
foundRepo.setSlackNotifyUnstable(slackSettings.getSlackNotifyUnstable());
foundRepo.setSlackNotifyFailure(slackSettings.getSlackNotifyFailure());
foundRepo.setSlackNotifyBackToNormal(slackSettings.getSlackNotifyBackToNormal());
foundRepo.setSlackNotifyRepeatedFailure(slackSettings.getSlackNotifyRepeatedFailure());
foundRepo.setSlackIncludeTestSummary(slackSettings.getSlackIncludeTestSummary());
foundRepo.save();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public abstract void setRepositoryConfigurationForRepositoryFromRequest(Reposito
String jenkinsServerName, boolean rebuildOnUpdate, boolean isJunitEnabled, String junitPath,
boolean artifactsEnabled, String artifactsPath, Integer maxVerifyChain, EmailSettings emailSettings,
boolean strictVerifyMode, Boolean preserveJenkinsJobConfig, boolean timestampJobOutputEnabled,
boolean ansiColorJobOutputEnabled, BuildTimeoutSettings buildTimeoutSettings)
boolean ansiColorJobOutputEnabled, BuildTimeoutSettings buildTimeoutSettings,
SlackSettings slackSettings)
throws SQLException, IllegalArgumentException;

public abstract ImmutableCollection<JenkinsServerConfiguration> getAllJenkinsServerConfigurations()
Expand Down Expand Up @@ -180,4 +181,138 @@ public Integer getBuildTimeout() {
}
}

public static class SlackSettings {

private final Boolean slackEnabled;
private final String slackTeamDomain;
private final String slackAuthToken;
private final String slackBuildServerUrl;
private final String slackRoom;
private final String slackCommitInfoChoice;
private final String slackCustomMessage;
private final Boolean slackStartNotification;
private final Boolean slackNotifySuccess;
private final Boolean slackNotifyAborted;
private final Boolean slackNotifyNotBuilt;
private final Boolean slackNotifyUnstable;
private final Boolean slackNotifyFailure;
private final Boolean slackNotifyBackToNormal;
private final Boolean slackNotifyRepeatedFailure;
private final Boolean slackIncludeTestSummary;
private final Boolean slackIncludeCustomMessage;

public SlackSettings() {
this(false,
"", "", "", "", "", "",
false, false, false, false, false, false, false, false, false, false);
}

public SlackSettings(
Boolean slackEnabled,
String slackTeamDomain,
String slackAuthToken,
String slackBuildServerUrl,
String slackRoom,
String slackCommitInfoChoice,
String slackCustomMessage,
Boolean slackStartNotification,
Boolean slackNotifySuccess,
Boolean slackNotifyAborted,
Boolean slackNotifyNotBuilt,
Boolean slackNotifyUnstable,
Boolean slackNotifyFailure,
Boolean slackNotifyBackToNormal,
Boolean slackNotifyRepeatedFailure,
Boolean slackIncludeTestSummary,
Boolean slackIncludeCustomMessage
) {
this.slackEnabled = slackEnabled;
this.slackTeamDomain = slackTeamDomain;
this.slackAuthToken = slackAuthToken;
this.slackBuildServerUrl = slackBuildServerUrl;
this.slackRoom = slackRoom;
this.slackCommitInfoChoice = slackCommitInfoChoice;
this.slackCustomMessage = slackCustomMessage;
this.slackStartNotification = slackStartNotification;
this.slackNotifySuccess = slackNotifySuccess;
this.slackNotifyAborted = slackNotifyAborted;
this.slackNotifyNotBuilt = slackNotifyNotBuilt;
this.slackNotifyUnstable = slackNotifyUnstable;
this.slackNotifyFailure = slackNotifyFailure;
this.slackNotifyBackToNormal = slackNotifyBackToNormal;
this.slackNotifyRepeatedFailure = slackNotifyRepeatedFailure;
this.slackIncludeTestSummary = slackIncludeTestSummary;
this.slackIncludeCustomMessage = slackIncludeCustomMessage;
}

public Boolean getSlackEnabled() {
return slackEnabled;
}

public String getSlackTeamDomain() {
return slackTeamDomain;
}

public String getSlackAuthToken() {
return slackAuthToken;
}

public String getSlackBuildServerUrl() {
return slackBuildServerUrl;
}

public String getSlackRoom() {
return slackRoom;
}

public String getSlackCommitInfoChoice() {
return slackCommitInfoChoice;
}

public String getSlackCustomMessage() {
return slackCustomMessage;
}

public Boolean getSlackStartNotification() {
return slackStartNotification;
}

public Boolean getSlackNotifySuccess() {
return slackNotifySuccess;
}

public Boolean getSlackNotifyAborted() {
return slackNotifyAborted;
}

public Boolean getSlackNotifyNotBuilt() {
return slackNotifyNotBuilt;
}

public Boolean getSlackNotifyUnstable() {
return slackNotifyUnstable;
}

public Boolean getSlackNotifyFailure() {
return slackNotifyFailure;
}

public Boolean getSlackNotifyBackToNormal() {
return slackNotifyBackToNormal;
}

public Boolean getSlackNotifyRepeatedFailure() {
return slackNotifyRepeatedFailure;
}

public Boolean getSlackIncludeTestSummary() {
return slackIncludeTestSummary;
}

public Boolean getSlackIncludeCustomMessage() {
return slackIncludeCustomMessage;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ public String generateJobXml(JobTemplate jobTemplate, Repository repo)
vc.put("isBuildTimeoutEnabled", rc.getBuildTimeoutEnabled());
vc.put("buildTimeout", rc.getBuildTimeout());

// Configure Slack
vc.put("slackEnabled", rc.getSlackEnabled());
// strings
vc.put("slackTeamDomain", rc.getSlackTeamDomain());
vc.put("slackAuthToken", rc.getSlackAuthToken());
vc.put("slackBuildServerUrl", rc.getSlackBuildServerUrl());
vc.put("slackRoom", rc.getSlackRoom());
vc.put("slackCommitInfoChoice", rc.getSlackCommitInfoChoice());
vc.put("slackCustomMessage", rc.getSlackCustomMessage());
// bools
vc.put("slackStartNotification", rc.getSlackStartNotification());
vc.put("slackNotifySuccess", rc.getSlackNotifySuccess());
vc.put("slackNotifyAborted", rc.getSlackNotifyAborted());
vc.put("slackNotifyNotBuilt", rc.getSlackNotifyNotBuilt());
vc.put("slackNotifyUnstable", rc.getSlackNotifyUnstable());
vc.put("slackNotifyFailure", rc.getSlackNotifyFailure());
vc.put("slackNotifyBackToNormal", rc.getSlackNotifyBackToNormal());
vc.put("slackNotifyRepeatedFailure", rc.getSlackNotifyRepeatedFailure());
vc.put("slackIncludeTestSummary", rc.getSlackIncludeTestSummary());
vc.put("slackIncludeCustomMessage", rc.getSlackIncludeCustomMessage());

// Add email notification stuff for all build types
vc.put("isEmailNotificationsEnabled", rc.getEmailNotificationsEnabled());
vc.put("emailRecipients", rc.getEmailRecipients());
Expand Down
Loading