Skip to content

Commit

Permalink
[JENKINS-9067] adding poll only on master option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Petti committed Mar 23, 2011
1 parent 3c80ed4 commit 23f722e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
34 changes: 29 additions & 5 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -211,6 +211,11 @@ public class PerforceSCM extends SCM {
private boolean useViewMaskForPolling = true;
private boolean useViewMaskForSyncing = false;

/**
* Sync only on master option.
*/
private boolean pollOnlyOnMaster = false;

/**
* charset options
*/
Expand Down Expand Up @@ -243,6 +248,7 @@ public PerforceSCM(
boolean wipeRepoBeforeBuild,
boolean dontUpdateClient,
boolean exposeP4Passwd,
boolean pollOnlyOnMaster,
String slaveClientNameFormat,
int firstChange,
PerforceRepositoryBrowser browser,
Expand All @@ -255,6 +261,7 @@ public PerforceSCM(
this.exposeP4Passwd = exposeP4Passwd;
this.p4Client = p4Client;
this.p4Port = p4Port;
this.pollOnlyOnMaster = pollOnlyOnMaster;
this.projectOptions = (projectOptions != null)
? projectOptions
: "noallwrite clobber nocompress unlocked nomodtime rmdir";
Expand Down Expand Up @@ -809,13 +816,22 @@ public boolean pollChanges(AbstractProject project, Launcher launcher,
Depot depot;

try {
//try to get an active node that the project is configured to use
Node buildNode = project.getLastBuiltOn();
if (!isNodeOnline(buildNode)){
if (pollOnlyOnMaster){
buildNode = null;
}
if (buildNode == null){
buildNode = getOnlineConfiguredNode(project);
} else {
//try to get an active node that the project is configured to use
buildNode = project.getLastBuiltOn();

if (!isNodeOnline(buildNode)){
buildNode = null;
}
if (buildNode == null && !pollOnlyOnMaster){
buildNode = getOnlineConfiguredNode(project);
}
if (pollOnlyOnMaster){
buildNode = null;
}
}
if (buildNode == null){
depot = getDepot(launcher,workspace,project);
Expand Down Expand Up @@ -2105,6 +2121,14 @@ public void setExcludedFiles(String files) {
excludedFiles = files;
}

public boolean isPollOnlyOnMaster() {
return pollOnlyOnMaster;
}

public void setPollOnlyOnMaster(boolean pollOnlyOnMaster) {
this.pollOnlyOnMaster = pollOnlyOnMaster;
}

public List<String> getAllLineEndChoices(){
List<String> allChoices = ((PerforceSCMDescriptor)this.getDescriptor()).getAllLineEndChoices();
ArrayList<String> choices = new ArrayList<String>();
Expand Down
Expand Up @@ -73,6 +73,10 @@
<f:checkbox field="disableSyncOnly" value="False"/>
</f:entry>

<f:entry title="Poll Only on Master" help="/plugin/perforce/help/pollOnlyOnMaster.html">
<f:checkbox field="pollOnlyOnMaster" value="False"/>
</f:entry>

<f:entry title="First Changelist to Track" help="/plugin/perforce/help/firstChange.html">
<f:textbox field="firstChange"
checkUrl="'${rootURL}/scm/PerforceSCM/checkChangeList?port='+escape(document.forms[1].p4Port.value)+'&amp;exe='+escape(document.forms[1].p4Exe.value)+'&amp;user='+escape(document.forms[1].p4User.value)+'&amp;pass='+escape(document.forms[1].p4Passwd.value)+'&amp;change='+escape(this.value)"/>
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/help/pollOnlyOnMaster.html
@@ -0,0 +1,7 @@
<div>
<p>
<b>Poll Only on Master</b>: enabling this setting will cause the perforce plugin to only ever poll using the master.
By default, the plugin will attempt to use any active nodes that the job is configured to use. In the case of volatile, on-demand environments,
greater stability may be acheived by enabling this option. Only enable this option if the perforce configuration in the job is known to work on the master.
</p>
</div>
8 changes: 4 additions & 4 deletions src/test/java/hudson/plugins/perforce/PerforceSCMTest.java
Expand Up @@ -22,7 +22,7 @@ public void testConfigRoundtrip() throws Exception {
PerforceSCM scm = new PerforceSCM(
"user", "pass", "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
false, true, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

// config roundtrip
Expand All @@ -43,7 +43,7 @@ public void testConfigPasswordEnctyptionAndDecription() throws Exception {
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
false, true, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

// config roundtrip
Expand All @@ -67,7 +67,7 @@ public void testDepotContainsUnencryptedPassword() throws Exception {
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
false, true, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");

project.setScm(scm);

Expand All @@ -81,7 +81,7 @@ public void testConfigSaveReloadAndSaveDoesNotDoubleEncryptThePassword() throws
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
false, true, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

// config roundtrip
Expand Down

0 comments on commit 23f722e

Please sign in to comment.