Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-34464] Bump structs version, add test for result roundtrip
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/org/jenkinsci/plugins/workflow/testMetaStep/EchoResultStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.jenkinsci.plugins.workflow.testMetaStep; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Result; | ||
import hudson.model.TaskListener; | ||
import org.jenkinsci.plugins.workflow.steps.Step; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
import org.jenkinsci.plugins.workflow.steps.StepExecution; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
|
||
import java.io.Serializable; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
public class EchoResultStep extends Step implements Serializable { | ||
|
||
private Result result; | ||
|
||
@DataBoundConstructor | ||
public EchoResultStep(Result result) { | ||
this.result = result; | ||
} | ||
|
||
public Result getResult() { | ||
return result; | ||
} | ||
|
||
@Override | ||
public StepExecution start(StepContext context) throws Exception { | ||
return new EchoResultStepExecution(this, context); | ||
} | ||
|
||
@Extension | ||
public static final class DescriptorImpl extends StepDescriptor { | ||
@Override | ||
public String getFunctionName() { | ||
return "echoResult"; | ||
} | ||
|
||
@Override | ||
public Set<? extends Class<?>> getRequiredContext() { | ||
return Collections.singleton(TaskListener.class); | ||
} | ||
} | ||
|
||
public static class EchoResultStepExecution extends StepExecution { | ||
private final EchoResultStep step; | ||
|
||
public EchoResultStepExecution(EchoResultStep s, StepContext context) { | ||
super(context); | ||
this.step = s; | ||
} | ||
|
||
@Override | ||
public boolean start() throws Exception { | ||
TaskListener listener = getContext().get(TaskListener.class); | ||
|
||
if (listener != null) | ||
listener.getLogger().println("Result is " + step.getResult()); | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void stop(Throwable cause) throws Exception { | ||
} | ||
} | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
} |