Skip to content
Permalink
Browse files

Added silent start option

When the Silent Start Mode is enabled there
will be no 'build started' messages sent back
to Gerrit.

Change-Id: I6bdfa62bc24bac71909638b93ae62ad1c877486e
  • Loading branch information...
Örjan Percy
Örjan Percy committed Jul 3, 2014
1 parent af9706b commit a50dbd590f9fa86155a331ed098efcd0be194466
@@ -1,8 +1,7 @@
/*
* The MIT License
*
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
* Copyright (c) 2010, 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -182,8 +181,15 @@ public synchronized void onStarted(AbstractBuild r, TaskListener listener) {
if (!cause.isSilentMode()) {
memory.started(cause.getEvent(), r);
updateTriggerContexts(r);
BuildsStartedStats stats = memory.getBuildsStartedStats(cause.getEvent());
NotificationFactory.getInstance().queueBuildStarted(r, listener, cause.getEvent(), stats);
GerritTrigger trigger = GerritTrigger.getTrigger(r.getProject());
boolean silentStartMode = false;
if (trigger != null) {
silentStartMode = trigger.isSilentStartMode();
}
if (!silentStartMode) {
BuildsStartedStats stats = memory.getBuildsStartedStats(cause.getEvent());
NotificationFactory.getInstance().queueBuildStarted(r, listener, cause.getEvent(), stats);
}
}
logger.info("Gerrit build [{}] Started for cause: [{}].", r, cause);
logger.info("MemoryStatus:\n{}", memory.getStatusReport(cause.getEvent()));
@@ -1,8 +1,7 @@
/*
* The MIT License
*
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
* Copyright (c) 2010, 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -142,6 +141,7 @@
private Integer gerritBuildNotBuiltCodeReviewValue;
private boolean silentMode;
private String notificationLevel;
private boolean silentStartMode;
private boolean escapeQuotes;
private boolean noNameAndEmailParameters;
private String dependencyJobsNames;
@@ -201,6 +201,7 @@
* Job specific Gerrit code review vote when a build is not built, null means
* that the global value should be used.
* @param silentMode Silent Mode on or off.
* @param silentStartMode Silent Start Mode on or off.
* @param escapeQuotes EscapeQuotes on or off.
* @param noNameAndEmailParameters Whether to create parameters containing name and email
* @param readableMessage Human readable message or not.
@@ -212,7 +213,7 @@
* @param buildNotBuiltMessage Message to write to Gerrit when all builds are not built
* @param buildUnsuccessfulFilepath Filename to retrieve Gerrit comment message from, in the case of an
* unsuccessful build.
* @param customUrl Custom URL to sen to Gerrit instead of build URL
* @param customUrl Custom URL to send to Gerrit instead of build URL
* @param serverName The selected server
* @param gerritSlaveId The selected slave associated to this job, if enabled in server configs
* @param triggerOnEvents The list of event types to trigger on.
@@ -237,6 +238,7 @@ public GerritTrigger(
Integer gerritBuildNotBuiltVerifiedValue,
Integer gerritBuildNotBuiltCodeReviewValue,
boolean silentMode,
boolean silentStartMode,
boolean escapeQuotes,
boolean noNameAndEmailParameters,
boolean readableMessage,
@@ -268,6 +270,7 @@ public GerritTrigger(
this.gerritBuildNotBuiltVerifiedValue = gerritBuildNotBuiltVerifiedValue;
this.gerritBuildNotBuiltCodeReviewValue = gerritBuildNotBuiltCodeReviewValue;
this.silentMode = silentMode;
this.silentStartMode = silentStartMode;
this.escapeQuotes = escapeQuotes;
this.noNameAndEmailParameters = noNameAndEmailParameters;
this.readableMessage = readableMessage;
@@ -405,7 +408,7 @@ public void stop() {
GerritProjectList.removeTriggerFromProjectList(this);
super.stop();
try {
removeListener();
removeListener();
} catch (IllegalStateException e) {
logger.error("I am too late!", e);
}
@@ -415,8 +418,6 @@ public void stop() {

/**
* Removes listener from the server.
*
*
*/
private void removeListener() {
PluginImpl plugin = PluginImpl.getInstance();
@@ -427,7 +428,7 @@ private void removeListener() {
logger.error("The Gerrit handler has not been initialized. BUG!");
}
} else {
logger.error("The plugin instance could not be found");
logger.error("The plugin instance could not be found");
}
}

@@ -717,7 +718,6 @@ protected ParametersAction createParameters(GerritTriggeredEvent event, Abstract
if (paramDefProp == null) {
return defValues;
}

/* Scan for all parameters with an associated default value */
for (ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();
@@ -1335,6 +1335,16 @@ public boolean isSilentMode() {
return silentMode;
}

/**
* If silent start mode is on or off. When silent start mode is on there will be no 'build started' message back
* to Gerrit. Default is false.
*
* @return true if silent start mode is on.
*/
public boolean isSilentStartMode() {
return silentStartMode;
}

/**
* Returns whom to notify.
*
@@ -1472,6 +1482,16 @@ public void setSilentMode(boolean silentMode) {
this.silentMode = silentMode;
}

/**
* Sets silent start mode to on or off. When silent start mode is on there will be no 'silent start' message
* back to Gerrit. Default is false.
*
* @param silentStartMode true if silent start mode should be on.
*/
public void setSilentStartMode(boolean silentStartMode) {
this.silentStartMode = silentStartMode;
}

/**
* Sets the value for whom to notify.
*
@@ -1813,7 +1833,6 @@ public FormValidation doUrlCheck(
if (value == null || value.isEmpty()) {
return FormValidation.error(Messages.EmptyError());
}

try {
URL url = new URL(value); // Check for protocol errors
url.toURI(); // Perform some extra checking
@@ -1977,7 +1996,6 @@ private void cancelJob(ParametersAction parameters) {
}
}
}

// Interrupt any currently running jobs.
for (Computer c : Hudson.getInstance().getComputers()) {
List<Executor> executors = new ArrayList<Executor>();
@@ -12,6 +12,12 @@
</f:entry>
</j:if>
<f:advanced>
<f:entry title="${%Silent Start Mode}"
field="silentStartMode"
help="/plugin/gerrit-trigger/trigger/help-SilentStartMode.html">
<f:checkbox name="silentStartMode"
checked="${it.silentStartMode}"/>
</f:entry>
<f:entry title="${%Escape Quotes in Parameter Values}" field="escapeQuotes"
help="/plugin/gerrit-trigger/trigger/help-EscapeQuotes.html">
<f:checkbox name="escapeQuotes" default="true" checked="${it.escapeQuotes}"/>
@@ -0,0 +1,2 @@
Sets silent start mode to on or off.
When silent start mode is on there will be no 'build started' messages sent back to Gerrit.
@@ -2,6 +2,7 @@
* The MIT License
*
* Copyright 2013 Joel Huttunen. All rights reserved.
* Copyright (c) 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -67,6 +68,24 @@ private GerritProject createGerritProject(String pattern, CompareType compareTyp
return config;
}

/**
* Creates GerritTrigger.
* @param gerritProjects the list of Gerrit projects.
* @param unreviewed is check unreviewed patches property allowed.
* @param silentMode is silentMode allowed.
* @param silentStartMode is silentStartMode allowed.
* @return GerritTrigger the created trigger.
*/
private GerritTrigger createGerritTrigger(
List<GerritProject> gerritProjects, boolean unreviewed, boolean silentMode, boolean silentStartMode) {
GerritTrigger trigger = Setup.createDefaultTrigger(null);
trigger.setGerritProjects(gerritProjects);
trigger.setAllowTriggeringUnreviewedPatches(unreviewed);
trigger.setSilentMode(silentMode);
trigger.setSilentStartMode(silentStartMode);
return trigger;
}

/**
* Creates GerritTrigger.
* @param gerritProjects the list of Gerrit projects.
@@ -80,6 +99,7 @@ private GerritTrigger createGerritTrigger(
trigger.setGerritProjects(gerritProjects);
trigger.setAllowTriggeringUnreviewedPatches(unreviewed);
trigger.setSilentMode(silentMode);
trigger.setSilentStartMode(false);
return trigger;
}

@@ -1,8 +1,7 @@
/*
* The MIT License
*
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
* Copyright (c) 2010, 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -283,7 +282,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}

/**
* Tests that initalizeTriggerOnEvents is run correctly by the start method.
* Tests that initializeTriggerOnEvents is run correctly by the start method.
*/
@Test
public void testInitializeTriggerOnEvents() {
@@ -292,8 +291,9 @@ public void testInitializeTriggerOnEvents() {
PowerMockito.when(PluginImpl.getInstance()).thenReturn(plugin);
AbstractProject project = PowerMockito.mock(AbstractProject.class);
when(project.getFullName()).thenReturn("MockedProject");
boolean silentStartMode = false;
GerritTrigger trigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
true, true, false, false, "", "", "", "", "", "", "", null, null, null,
true, silentStartMode, true, false, false, "", "", "", "", "", "", "", null, null, null,
null, false, false, "", null);
trigger = spy(trigger);
Object triggerOnEvents = Whitebox.getInternalState(trigger, "triggerOnEvents");
@@ -1730,9 +1730,9 @@ public void shouldReturnGlobalSlavesWhenConfigured() {
@Test
public void shouldReturnSlaveSelectedInJobWhenConfigured() {
ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true,
false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
false, false, "", null);
GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, false, true,
false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
false, false, "", null);

when(replicationConfigMock.isEnableReplication()).thenReturn(true);
when(replicationConfigMock.isEnableSlaveSelectionInJobs()).thenReturn(true);
@@ -1751,9 +1751,9 @@ public void shouldReturnSlaveSelectedInJobWhenConfigured() {
@Test
public void shouldReturnDefaultSlaveWhenJobConfiguredSlaveDoesNotExist() {
ReplicationConfig replicationConfigMock = setupReplicationConfigMock();
GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true,
false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
false, false, "", null);
GerritTrigger gerritTrigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, false, true,
false, false, "", "", "", "", "", "", "", null, PluginImpl.DEFAULT_SERVER_NAME, "slaveUUID", null,
false, false, "", null);

// Replication is configured at job level but slave and default no longer exist.
when(replicationConfigMock.isEnableReplication()).thenReturn(true);
@@ -1,8 +1,7 @@
/*
* The MIT License
*
* Copyright 2011 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
* Copyright (c) 2011, 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -86,7 +85,7 @@ public static FreeStyleProject createGerritTriggeredJob(JenkinsRule rule,
Collections.singletonList(new Branch(CompareType.ANT, "**")), null, null, null));
p.addTrigger(new GerritTrigger(projects, null,
null, null, null, null, null, null, null, null, null, null,
false, true, false, false, null, null, null, null, null, null, null,
false, false, true, false, false, null, null, null, null, null, null, null,
null, serverName, null, null, false, false, null, null));
rule.submit(rule.createWebClient().getPage(p, "configure").getFormByName("config"));
return p;
@@ -114,7 +113,7 @@ public static FreeStyleProject createGerritDynamicTriggeredJob(JenkinsRule rule,
URI uri = file.toURI();
String filepath = uri.toURL().toString();
GerritTrigger trigger = new GerritTrigger(projects, null,
null, null, null, null, null, null, null, null, null, null, false,
null, null, null, null, null, null, null, null, null, null, false, false,
false, false, false, null, null, null, null, null, null, null, null,
PluginImpl.DEFAULT_SERVER_NAME, null, list, true, false, filepath, null);
p.addTrigger(trigger);
@@ -158,7 +157,7 @@ public static FreeStyleProject createGerritTriggeredJobForCommentAdded(JenkinsRu
list.add(event);
p.addTrigger(new GerritTrigger(projects, null,
null, null, null, null, null, null, null, null, null, null,
false, true, false, false, null, null, null, null, null, null, null,
false, false, true, false, false, null, null, null, null, null, null, null,
null, serverName, null, list, false, false, null, null));
rule.submit(rule.createWebClient().getPage(p, "configure").getFormByName("config"));
return p;
@@ -1,8 +1,7 @@
/*
* The MIT License
*
* Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
* Copyright 2012 Sony Mobile Communications AB. All rights reserved.
* Copyright (c) 2010, 2014 Sony Mobile Communications Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -524,9 +523,11 @@ public static GerritTrigger createDefaultTrigger(AbstractProject project) {
PluginPatchsetCreatedEvent pluginEvent = new PluginPatchsetCreatedEvent();
List<PluginGerritEvent> triggerOnEvents = new LinkedList<PluginGerritEvent>();
triggerOnEvents.add(pluginEvent);
boolean silentMode = true;
boolean silentStart = false;

GerritTrigger trigger = new GerritTrigger(null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
true, true, false, false, "", "", "", "", "", "", "", null,
silentMode, silentStart, true, false, false, "", "", "", "", "", "", "", null,
PluginImpl.DEFAULT_SERVER_NAME, null, triggerOnEvents, false, false, "", null);

if (project != null) {

7 comments on commit a50dbd5

@rinrinne

This comment has been minimized.

Copy link
Member

replied Nov 11, 2014

What is difference between "silent mode" and "silent start mode"?

I think it should be clarified in help text.

@TWestling

This comment has been minimized.

Copy link
Member

replied Nov 12, 2014

The difference is that silent start option attempts to reduce spam by not sending e-mails when starting the build. I agree, this should be clarified in the help.

@orjanpercy

This comment has been minimized.

Copy link

replied Nov 12, 2014

There is a html help text in src/main/webapp/trigger/help-SilentStartMode.html, albeit small.

@rinrinne

This comment has been minimized.

Copy link
Member

replied Nov 13, 2014

I compared those features again. Then I'd like to change my suggestion as below:

  • It should be fixed in description text (means the title attribute in f:entry element)

Silent Mode includes a couple of feature.

  • No build started/failure/successful messages are sent back to Gerrit
  • The result of build is not included to the verdict of a patchset

But Silent Start Mode provides a simple feature not to send back build start message to Gerrit. So it can be represented by description of item. Hence I think we don't need to give this feature a name like Silent Start Mode.

@orjanpercy

This comment has been minimized.

Copy link

replied Nov 13, 2014

I understand you don't like the feature name, but what do you suggest it should be called instead?

@rinrinne

This comment has been minimized.

Copy link
Member

replied Nov 13, 2014

Would you like "Don't send back comment to Gerrit when build started."?

@rsandell

This comment has been minimized.

Copy link
Member

replied Nov 14, 2014

That is a bit too long imho. But something like it could be put as a description to separate it more clearly from silent mode.

Please sign in to comment.
You can’t perform that action at this time.