Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Actually fixing restartability of input step.
(Turns out an injected Step is not resumed, so you need to clone it if you need it later!)
JENKINS-25889 still broken but this does not seem to be critical.
Originally-Committed-As: f1ea316dd7af44170f7f0745bf20167774b212a6
  • Loading branch information
jglick committed Dec 3, 2014
1 parent fa35a64 commit df6b20c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 28 deletions.
@@ -0,0 +1,69 @@
/*
* The MIT License
*
* Copyright 2014 Jesse Glick.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.workflow.steps.input;

import com.google.common.base.Function;
import java.io.IOException;
import org.jenkinsci.plugins.workflow.SingleJobTestBase;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution;
import org.junit.Test;
import org.junit.runners.model.Statement;

public class InputStepRestartTest extends SingleJobTestBase {

@Test public void restart() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition("input 'paused'"));
startBuilding();
waitForWorkflowToSuspend();
assertTrue(b.isBuilding());
}
});
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
rebuildContext(story.j);
assertThatWorkflowIsSuspended();
StepExecution.applyAll(InputStepExecution.class, new Function<InputStepExecution,Void>() {
@Override public Void apply(InputStepExecution exec) {
try {
exec.doProceedEmpty();
} catch (IOException x) {
assert false : x;
}
return null;
}
}).get();
waitForWorkflowToComplete();
assertBuildCompletedSuccessfully();
}
});
}

}
@@ -1,51 +1,26 @@
package org.jenkinsci.plugins.workflow.support.steps.input;

import hudson.Extension;
import hudson.FilePath;
import hudson.Util;
import hudson.model.Failure;
import hudson.model.FileParameterValue;
import hudson.model.ModelObject;
import hudson.model.ParameterDefinition;
import hudson.model.ParameterValue;
import hudson.model.Run;
import hudson.model.User;
import hudson.util.HttpResponses;
import jenkins.model.Jenkins;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.acegisecurity.Authentication;
import org.acegisecurity.GrantedAuthority;
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.kohsuke.stapler.interceptor.RequirePOST;

/**
* {@link Step} that pauses for human input.
*
* @author Kohsuke Kawaguchi
*/
public class InputStep extends AbstractStepImpl implements Serializable {
public class InputStep extends AbstractStepImpl implements Serializable, Cloneable {
private final String message;

/**
Expand Down Expand Up @@ -76,6 +51,10 @@ public InputStep(String message) {
this.message = message;
}

@Override public InputStep clone() throws CloneNotSupportedException {
return (InputStep) super.clone();
}

@DataBoundSetter
public void setId(String id) {
this.id = capitalize(Util.fixEmpty(id));
Expand Down
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.workflow.support.steps.input;

import com.google.inject.Inject;
import hudson.FilePath;
import hudson.Util;
import hudson.console.HyperlinkNote;
Expand All @@ -23,7 +24,6 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.interceptor.RequirePOST;

import javax.inject.Inject;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.HashMap;
Expand All @@ -50,10 +50,13 @@ public class InputStepExecution extends AbstractStepExecutionImpl implements Mod
*/
private Outcome outcome;

@Inject transient InputStep input;
@Inject(optional=true) transient InputStep _input;
InputStep input;

@Override
public boolean start() throws Exception {
input = _input.clone(); // serialize a copy

// record this input
getPauseAction().add(this);

Expand Down

0 comments on commit df6b20c

Please sign in to comment.