From 3035d97b94750ad46ca9744ab57f27a807ed1130 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 2 May 2017 20:16:13 -0400 Subject: [PATCH 01/16] Sketch of using disabled functionality as it would exist in ParameterizedJob. --- .../plugins/workflow/job/WorkflowJob.java | 36 +++++++++++++++++++ .../job/WorkflowJob/configure-entries.jelly | 1 + .../workflow/job/WorkflowJob/main.jelly | 1 + 3 files changed, 38 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index d86a4ed8..41bc4389 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -54,6 +54,7 @@ import hudson.model.TaskListener; import hudson.model.TopLevelItem; import hudson.model.TopLevelItemDescriptor; +import hudson.model.listeners.ItemListener; import hudson.model.listeners.SCMListener; import hudson.model.queue.CauseOfBlockage; import hudson.model.queue.QueueTaskFuture; @@ -124,6 +125,7 @@ public final class WorkflowJob extends Job implements B * TODO is it important to persist this? {@link hudson.model.AbstractProject#pollingBaseline} is not persisted. */ private transient volatile Map pollingBaselines; + private volatile boolean disabled; public WorkflowJob(ItemGroup parent, String name) { super(parent, name); @@ -197,6 +199,8 @@ public void setDefinition(FlowDefinition definition) { } else { quietPeriod = null; } + + // TODO call makeDisabled } @@ -304,6 +308,38 @@ public boolean isParameterized() { return createParameterizedJobMixIn().isParameterized(); } + // TODO @Override + public boolean isDisabled() { + return disabled; + } + + @Restricted(DoNotUse.class) + // TODO @Override + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + // TODO @Override + public boolean supportsMakeDisabled() { + return true; // TODO but not if this is a branch project + } + + // TODO use parent version + public void makeDisabled(boolean b) throws IOException { + if (isDisabled() == b) { + return; // noop + } + if (b && !supportsMakeDisabled()) { + return; // do nothing if the disabling is unsupported + } + setDisabled(b); + if (b) { + Jenkins.getInstance().getQueue().cancel(this); + } + save(); + ItemListener.fireOnUpdated(this); + } + @SuppressWarnings("deprecation") @Override public hudson.model.BuildAuthorizationToken getAuthToken() { return authToken; diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/configure-entries.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/configure-entries.jelly index bc003bcd..44937a4c 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/configure-entries.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/configure-entries.jelly @@ -25,6 +25,7 @@ --> + diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly index 21af3f1d..9064a3a2 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly @@ -25,6 +25,7 @@ --> + From 9fdb3d6f4ae5ac288140564cf9e49c3b0e941b6a Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 2 May 2017 20:23:56 -0400 Subject: [PATCH 02/16] FindBugs --- .../java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 41bc4389..c58a53c8 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -334,7 +334,7 @@ public void makeDisabled(boolean b) throws IOException { } setDisabled(b); if (b) { - Jenkins.getInstance().getQueue().cancel(this); + Jenkins.getActiveInstance().getQueue().cancel(this); } save(); ItemListener.fireOnUpdated(this); From 867c3fc02fb6c27659970377e3247913de7fab05 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 13:23:21 -0400 Subject: [PATCH 03/16] makeDisabled.jelly equivalent. --- .../workflow/job/WorkflowJob/main.jelly | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly index 9064a3a2..7f90f9c1 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly @@ -25,7 +25,30 @@ --> - + + + + + +
+
+ ${%This project is currently disabled} + + + + +
+
+ +
+
+ + + + +
+
+
From 0d656178898ca98726f2064d8a87e6b3cd801cd6 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 19:18:34 -0400 Subject: [PATCH 04/16] Updates. --- .../plugins/workflow/job/WorkflowJob.java | 26 ++++++++++++++----- .../workflow/job/WorkflowJob/main.jelly | 2 +- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index c58a53c8..3ab0022d 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -35,6 +35,7 @@ import hudson.init.InitMilestone; import hudson.init.Initializer; import hudson.model.Action; +import hudson.model.BallColor; import hudson.model.BuildableItem; import hudson.model.Cause; import hudson.model.Computer; @@ -200,7 +201,7 @@ public void setDefinition(FlowDefinition definition) { quietPeriod = null; } - // TODO call makeDisabled + makeDisabled(json.optBoolean("disable")); } @@ -262,7 +263,11 @@ public void setDefinition(FlowDefinition definition) { return buildMixIn.createHistoryWidget(); } + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override @Override public Queue.Executable createExecutable() throws IOException { + if (isDisabled()) { + return null; + } return buildMixIn.newBuild(); } @@ -308,23 +313,23 @@ public boolean isParameterized() { return createParameterizedJobMixIn().isParameterized(); } - // TODO @Override + // TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override public boolean isDisabled() { return disabled; } @Restricted(DoNotUse.class) - // TODO @Override + // TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override public void setDisabled(boolean disabled) { this.disabled = disabled; } - // TODO @Override + // TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override public boolean supportsMakeDisabled() { return true; // TODO but not if this is a branch project } - // TODO use parent version + // TODO https://github.com/jenkinsci/jenkins/pull/2866 use parent version public void makeDisabled(boolean b) throws IOException { if (isDisabled() == b) { return; // noop @@ -340,6 +345,14 @@ public void makeDisabled(boolean b) throws IOException { ItemListener.fireOnUpdated(this); } + @Override public BallColor getIconColor() { + if (isDisabled()) { + return isBuilding() ? BallColor.DISABLED_ANIME : BallColor.DISABLED; + } else { + return super.getIconColor(); + } + } + @SuppressWarnings("deprecation") @Override public hudson.model.BuildAuthorizationToken getAuthToken() { return authToken; @@ -699,8 +712,9 @@ public void replaceAction(Action a) { } @Override protected void performDelete() throws IOException, InterruptedException { - super.performDelete(); + makeDisabled(true); // TODO call SCM.processWorkspaceBeforeDeletion + super.performDelete(); } @Initializer(before=InitMilestone.EXTENSIONS_AUGMENTED) diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly index 7f90f9c1..b9ec23aa 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly @@ -25,7 +25,7 @@ --> - + From 7963f3791bb5c1ec65103a9d29e8d7d54df895b8 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 19:35:26 -0400 Subject: [PATCH 05/16] [JENKINS-34716] doPolling and schedulePolling. --- .../plugins/workflow/job/WorkflowJob.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 3ab0022d..405d7e55 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -36,6 +36,7 @@ import hudson.init.Initializer; import hudson.model.Action; import hudson.model.BallColor; +import hudson.model.BuildAuthorizationToken; import hudson.model.BuildableItem; import hudson.model.Cause; import hudson.model.Computer; @@ -623,6 +624,31 @@ public void replaceAction(Action a) { return typical; } + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override + public boolean schedulePolling() { + if (isDisabled()) { + return false; + } + SCMTrigger scmt = getSCMTrigger(); + if (scmt == null) { + return false; + } + scmt.run(); + return true; + } + + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override + @SuppressWarnings("deprecation") + public void doPolling(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { + if (!(this instanceof SCMTriggerItem)) { + rsp.sendError(404); + return; + } + BuildAuthorizationToken.checkPermission((Job) this, getAuthToken(), req, rsp); + schedulePolling(); + rsp.sendRedirect("."); + } + @SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull") @Override public PollingResult poll(TaskListener listener) { // TODO call SCMPollListener From 221d176342a15915aabe5ecfc1c95a9857b1f75b Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:06:26 -0400 Subject: [PATCH 06/16] isBuildable --- .../java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 405d7e55..82b19b04 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -221,7 +221,8 @@ public void setDefinition(FlowDefinition definition) { } } } - return true; // why not? + // TODO https://github.com/jenkinsci/jenkins/pull/2866: return ParameterizedJobMixIn.ParameterizedJob.super.isBuildable(); + return !isDisabled() && !isHoldOffBuildUntilSave(); } @Override protected RunMap _getRuns() { @@ -330,7 +331,7 @@ public boolean supportsMakeDisabled() { return true; // TODO but not if this is a branch project } - // TODO https://github.com/jenkinsci/jenkins/pull/2866 use parent version + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override public void makeDisabled(boolean b) throws IOException { if (isDisabled() == b) { return; // noop From 3051b23ac164e7788277960e16accbd4f1b37059 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:10:48 -0400 Subject: [PATCH 07/16] =?UTF-8?q?No=20need=20to=20override=20supportsMakeD?= =?UTF-8?q?isabled=20for=20a=20branch=20project=E2=80=94these=20will=20hav?= =?UTF-8?q?e=20denied=20CONFIGURE=20anyway.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 82b19b04..6e86173a 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -328,7 +328,7 @@ public void setDisabled(boolean disabled) { // TODO https://github.com/jenkinsci/jenkins/pull/2866 @Override public boolean supportsMakeDisabled() { - return true; // TODO but not if this is a branch project + return true; } // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override From ae283ffbe1e7e917686386f8948f161b7a519b18 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:18:40 -0400 Subject: [PATCH 08/16] Extras picked up from #23. --- .../org/jenkinsci/plugins/workflow/job/WorkflowJob.java | 5 +++++ .../jenkinsci/plugins/workflow/job/WorkflowRunTest.java | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 6e86173a..aaf16379 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -652,6 +652,11 @@ public void doPolling(StaplerRequest req, StaplerResponse rsp) throws IOExceptio @SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull") @Override public PollingResult poll(TaskListener listener) { + if (!isBuildable()) { + listener.getLogger().println("Build disabled"); + return PollingResult.NO_CHANGES; + } + // TODO 2.11+ call SCMDecisionHandler // TODO call SCMPollListener WorkflowRun lastBuild = getLastBuild(); if (lastBuild == null) { diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java index 7f117a1f..843f049b 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java @@ -153,6 +153,10 @@ public void iconColor() throws Exception { assertFalse(b1.hasntStartedYet()); assertColor(b1, BallColor.BLUE); + p.makeDisabled(true); + assertColor(b1, BallColor.DISABLED); + p.makeDisabled(false); + // get another one going q = p.scheduleBuild2(0); WorkflowRun b2 = q.getStartCondition().get(); @@ -162,6 +166,10 @@ public void iconColor() throws Exception { assertFalse(b2.hasntStartedYet()); assertColor(b2, BallColor.BLUE_ANIME); + p.makeDisabled(true); + assertColor(b1, BallColor.DISABLED_ANIME); + p.makeDisabled(false); + SemaphoreStep.waitForStart("wait/2", b2); // at the pause point, it should be still blinking gray From 57cfe1243009d87d4ab72882dbeb2f68f7d85a2e Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:39:32 -0400 Subject: [PATCH 09/16] Broken Jelly page due to missing xmlns. --- .../org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly index b9ec23aa..fae573e9 100644 --- a/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly +++ b/src/main/resources/org/jenkinsci/plugins/workflow/job/WorkflowJob/main.jelly @@ -24,7 +24,7 @@ ~ THE SOFTWARE. --> - + From ac641ad8523e49439ccee7ce1bc87f398ac25af0 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:39:39 -0400 Subject: [PATCH 10/16] FindBugs --- .../java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index aaf16379..67a130f2 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -641,10 +641,6 @@ public boolean schedulePolling() { // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override @SuppressWarnings("deprecation") public void doPolling(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { - if (!(this instanceof SCMTriggerItem)) { - rsp.sendError(404); - return; - } BuildAuthorizationToken.checkPermission((Job) this, getAuthToken(), req, rsp); schedulePolling(); rsp.sendRedirect("."); From 41c072a7f1cede42598dbde4c9cc6275f22f40e3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:44:20 -0400 Subject: [PATCH 11/16] Forgot to copy doDisable/doEnable. --- .../plugins/workflow/job/WorkflowJob.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java index 67a130f2..ac3bfe4f 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/job/WorkflowJob.java @@ -102,6 +102,8 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.DoNotUse; import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.HttpRedirect; +import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -347,6 +349,22 @@ public void makeDisabled(boolean b) throws IOException { ItemListener.fireOnUpdated(this); } + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override + @RequirePOST + public HttpResponse doDisable() throws IOException, ServletException { + checkPermission(CONFIGURE); + makeDisabled(true); + return new HttpRedirect("."); + } + + // TODO https://github.com/jenkinsci/jenkins/pull/2866 remove override + @RequirePOST + public HttpResponse doEnable() throws IOException, ServletException { + checkPermission(CONFIGURE); + makeDisabled(false); + return new HttpRedirect("."); + } + @Override public BallColor getIconColor() { if (isDisabled()) { return isBuilding() ? BallColor.DISABLED_ANIME : BallColor.DISABLED; From 719ef1672b4a165fa0853d872e0d7d1c8bf20c25 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:44:37 -0400 Subject: [PATCH 12/16] Smoke test of disabled feature. --- .../plugins/workflow/job/WorkflowJobTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java index 2826da87..a6f31829 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java @@ -1,5 +1,9 @@ package org.jenkinsci.plugins.workflow.job; +import com.gargoylesoftware.htmlunit.HttpMethod; +import com.gargoylesoftware.htmlunit.WebRequest; +import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; +import com.gargoylesoftware.htmlunit.html.HtmlForm; import hudson.model.Result; import hudson.security.WhoAmI; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; @@ -46,4 +50,25 @@ public void addAction() throws Exception { assertNotNull(p.getAction(WhoAmI.class)); } + @Issue("JENKINS-27299") + @Test public void disabled() throws Exception { + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); + assertFalse(p.isDisabled()); + assertTrue(p.isBuildable()); + JenkinsRule.WebClient wc = j.createWebClient(); + j.submit(wc.getPage(p).getHtmlElementById("disable-project")); + assertTrue(p.isDisabled()); + assertFalse(p.isBuildable()); + HtmlForm form = wc.getPage(p, "configure").getFormByName("config"); + HtmlCheckBoxInput checkbox = form.getInputByName("disable"); + assertTrue(checkbox.isChecked()); + checkbox.setChecked(false); + j.submit(form); + assertFalse(p.isDisabled()); + wc.getPage(new WebRequest(wc.createCrumbedUrl(p.getUrl() + "disable"), HttpMethod.POST)); + assertTrue(p.isDisabled()); + assertNull(p.scheduleBuild2(0)); + // TODO https://github.com/jenkinsci/jenkins/pull/2866 reënable by CLI + } + } From cdeec45dfd1cceff7b9166f524cf5dec6d3ae5c3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 20:48:31 -0400 Subject: [PATCH 13/16] Also demonstrating that disabling a job does not affect a build in progress, even across Jenkins restarts. --- .../workflow/job/WorkflowRunRestartTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunRestartTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunRestartTest.java index 7d3dbc4b..303426ae 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunRestartTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunRestartTest.java @@ -33,6 +33,7 @@ import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl; import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; import org.jenkinsci.plugins.workflow.steps.StepContextParameter; +import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; import static org.junit.Assert.*; import org.junit.ClassRule; import org.junit.Rule; @@ -50,6 +51,29 @@ public class WorkflowRunRestartTest { @ClassRule public static BuildWatcher buildWatcher = new BuildWatcher(); @Rule public RestartableJenkinsRule story = new RestartableJenkinsRule(); + @Issue("JENKINS-27299") + @Test public void disabled() { + story.addStep(new Statement() { + @Override public void evaluate() throws Throwable { + WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p"); + p.setDefinition(new CpsFlowDefinition("node {semaphore 'wait'}")); + WorkflowRun b = p.scheduleBuild2(0).waitForStart(); + SemaphoreStep.waitForStart("wait/1", b); + p.makeDisabled(true); + } + }); + story.addStep(new Statement() { + @Override public void evaluate() throws Throwable { + WorkflowJob p = story.j.jenkins.getItemByFullName("p", WorkflowJob.class); + assertTrue(p.isDisabled()); + WorkflowRun b = p.getBuildByNumber(1); + assertTrue(b.isBuilding()); + SemaphoreStep.success("wait/1", null); + story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)); + } + }); + } + @Issue("JENKINS-25550") @Test public void hardKill() throws Exception { story.addStep(new Statement() { From a8c5b5f90e3a9bbfa31b9813efc0e01ee131d3ed Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Thu, 4 May 2017 21:04:29 -0400 Subject: [PATCH 14/16] Forgot that disabling a project changes the icon color of the project but not of builds. --- .../org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java index 843f049b..19954e88 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowRunTest.java @@ -154,7 +154,7 @@ public void iconColor() throws Exception { assertColor(b1, BallColor.BLUE); p.makeDisabled(true); - assertColor(b1, BallColor.DISABLED); + assertSame(BallColor.DISABLED, p.getIconColor()); p.makeDisabled(false); // get another one going @@ -167,7 +167,7 @@ public void iconColor() throws Exception { assertColor(b2, BallColor.BLUE_ANIME); p.makeDisabled(true); - assertColor(b1, BallColor.DISABLED_ANIME); + assertSame(BallColor.DISABLED_ANIME, p.getIconColor()); p.makeDisabled(false); SemaphoreStep.waitForStart("wait/2", b2); From 7ecd9856e6b5474af804d45d1d8054848a8d6cf3 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 5 May 2017 14:57:37 -0400 Subject: [PATCH 15/16] [JENKINS-34716] Verifying doPolling in a test. --- pom.xml | 28 +++++++++++++++++++ .../plugins/workflow/job/WorkflowJobTest.java | 26 +++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/pom.xml b/pom.xml index 4fcd0ecd..6e2e8b1f 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,8 @@ 2.19 false 2.2 + 2.1.1 + 3.2.0 @@ -109,5 +111,31 @@ 2.0 test + + org.jenkins-ci.plugins + scm-api + ${scm-api-plugin.version} + test + + + org.jenkins-ci.plugins + scm-api + ${scm-api-plugin.version} + tests + test + + + org.jenkins-ci.plugins + git + ${git-plugin.version} + test + + + org.jenkins-ci.plugins + git + ${git-plugin.version} + tests + test + diff --git a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java index a6f31829..a4b24472 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/job/WorkflowJobTest.java @@ -5,8 +5,12 @@ import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; import com.gargoylesoftware.htmlunit.html.HtmlForm; import hudson.model.Result; +import hudson.plugins.git.GitSCM; import hudson.security.WhoAmI; +import hudson.triggers.SCMTrigger; +import jenkins.plugins.git.GitSampleRepoRule; import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; +import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition; import static org.junit.Assert.*; import org.junit.Rule; import org.junit.Test; @@ -14,7 +18,9 @@ import org.jvnet.hudson.test.JenkinsRule; public class WorkflowJobTest { + @Rule public JenkinsRule j = new JenkinsRule(); + @Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule(); @Issue("JENKINS-40255") @Test public void getSCM() throws Exception { @@ -42,6 +48,26 @@ public class WorkflowJobTest { assertEquals("Expecting zero SCMs",0, p.getSCMs().size()); } + @Issue("JENKINS-34716") + @Test public void polling() throws Exception { + sampleRepo.init(); + sampleRepo.write("Jenkinsfile", "echo 'first version'"); + sampleRepo.git("add", "Jenkinsfile"); + sampleRepo.git("commit", "-m", "init"); + WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); + p.addTrigger(new SCMTrigger("")); + p.setDefinition(new CpsScmFlowDefinition(new GitSCM(sampleRepo.toString()), "Jenkinsfile")); + j.assertLogContains("first version", j.buildAndAssertSuccess(p)); + sampleRepo.write("Jenkinsfile", "echo 'second version'"); + sampleRepo.git("commit", "-a", "-m", "init"); + j.jenkins.setQuietPeriod(0); + j.createWebClient().getPage(new WebRequest(j.createWebClient().createCrumbedUrl(p.getUrl() + "polling"), HttpMethod.POST)); + j.waitUntilNoActivity(); + WorkflowRun b2 = p.getLastBuild(); + assertEquals(2, b2.getNumber()); + j.assertLogContains("second version", b2); + } + @Test public void addAction() throws Exception { WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p"); From c4a4f04d5fb7092abe416f6e04200bd9663c21ec Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Fri, 5 May 2017 15:02:31 -0400 Subject: [PATCH 16/16] Transitive plugin deps. --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 6e2e8b1f..b61e6cf1 100644 --- a/pom.xml +++ b/pom.xml @@ -137,5 +137,17 @@ tests test + + org.jenkins-ci.plugins + mailer + 1.18 + test + + + org.jenkins-ci.plugins + junit + 1.6 + test +