Skip to content
Permalink
Browse files

Merge pull request #98 from jenkinsci/store-step-for-flownode-jenkins…

…-37324

[JENKINS-37324] Store parameter info for steps as an action on the flownode
  • Loading branch information...
svanoort committed May 22, 2017
2 parents c6dfd25 + 1e970d5 commit 4d402bb2bf5828b141ed01c70c8dfcde59a9e9d1
10 pom.xml
@@ -73,12 +73,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.9</version>
<version>2.10</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.11</version>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
@@ -148,6 +148,12 @@
<version>2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-input-step</artifactId>
@@ -30,14 +30,18 @@
import groovy.lang.GString;
import groovy.lang.GroovyObject;
import groovy.lang.GroovyObjectSupport;
import hudson.EnvVars;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Queue;
import hudson.model.Run;
import hudson.model.TaskListener;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.structs.describable.DescribableModel;
import org.jenkinsci.plugins.structs.describable.DescribableParameter;
import org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable;
import org.jenkinsci.plugins.workflow.cps.actions.ArgumentsActionImpl;
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode;
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
@@ -82,6 +86,8 @@
import org.kohsuke.stapler.ClassDescriptor;
import org.kohsuke.stapler.NoStaplerConstructorException;

import javax.annotation.Nonnull;

/**
* Scaffolding to experiment with the call into {@link Step}.
*
@@ -93,6 +99,8 @@
private transient CpsFlowExecution exec;
private transient Map<String,StepDescriptor> functions;

private static final Logger LOGGER = Logger.getLogger(DSL.class.getName());

public DSL(FlowExecutionOwner handle) {
this.handle = handle;
}
@@ -101,6 +109,17 @@ protected Object readResolve() throws IOException {
return this;
}

private static final String KEEP_STEP_ARGUMENTS_PROPERTYNAME = (DSL.class.getName()+".keepStepArguments");

private static boolean isKeepStepArguments = StringUtils.isEmpty(System.getProperty(KEEP_STEP_ARGUMENTS_PROPERTYNAME))
|| Boolean.parseBoolean(System.getProperty(KEEP_STEP_ARGUMENTS_PROPERTYNAME));

/** Tell us if we should store {@link Step} arguments in an {@link org.jenkinsci.plugins.workflow.actions.ArgumentsAction}
* or simply discard them (if set to false, explicitly) */
public static boolean isKeepStepArguments() {
return isKeepStepArguments;
}

/**
* Executes the {@link Step} implementation specified by the name argument.
*
@@ -182,6 +201,22 @@ protected Object invokeStep(StepDescriptor d, Object args) {
d.checkContextAvailability(context);
Thread.currentThread().setContextClassLoader(CpsVmExecutorService.ORIGINAL_CONTEXT_CLASS_LOADER.get());
s = d.newInstance(ps.namedArgs);
try {
// No point storing empty arguments, and ParallelStep is a special case where we can't store its closure arguments
if (ps.namedArgs != null && !(ps.namedArgs.isEmpty()) && isKeepStepArguments() && !(s instanceof ParallelStep)) {
// Get the environment variables to find ones that might be credentials bindings
Computer comp = context.get(Computer.class);
EnvVars allEnv = new EnvVars(context.get(EnvVars.class));
if (comp != null && allEnv != null) {
allEnv.entrySet().removeAll(comp.getEnvironment().entrySet());
}
an.addAction(new ArgumentsActionImpl(ps.namedArgs, allEnv));
}
} catch (Exception e) {
// Avoid breaking execution because we can't store some sort of crazy Step argument
LOGGER.log(Level.WARNING, "Error storing the arguments for step: "+d.getFunctionName(), e);
}

StepExecution e = s.start(context);
thread.setStep(e);
sync = e.start();

0 comments on commit 4d402bb

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