|
24 | 24 |
|
25 | 25 | package org.jenkinsci.plugins.workflow.cps; |
26 | 26 |
|
| 27 | +import com.google.common.util.concurrent.Futures; |
| 28 | +import com.google.common.util.concurrent.ListenableFuture; |
27 | 29 | import groovy.lang.GroovyObjectSupport; |
28 | 30 | import hudson.EnvVars; |
29 | 31 | import hudson.Extension; |
|
32 | 34 | import hudson.model.TaskListener; |
33 | 35 | import hudson.util.LogTaskListener; |
34 | 36 | import java.io.IOException; |
35 | | -import java.io.Serializable; |
36 | 37 | import java.util.Collection; |
37 | 38 | import java.util.Collections; |
38 | 39 | import java.util.Map; |
39 | 40 | import java.util.TreeMap; |
40 | 41 | import java.util.logging.Level; |
41 | 42 | import java.util.logging.Logger; |
42 | 43 | import edu.umd.cs.findbugs.annotations.NonNull; |
| 44 | +import hudson.model.Queue; |
43 | 45 | import jenkins.model.RunAction2; |
44 | 46 | import org.jenkinsci.plugins.workflow.flow.FlowCopier; |
45 | 47 | import org.jenkinsci.plugins.workflow.flow.FlowExecution; |
46 | 48 | import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; |
47 | 49 | import org.jenkinsci.plugins.workflow.graph.FlowNode; |
| 50 | +import org.jenkinsci.plugins.workflow.pickles.Pickle; |
48 | 51 | import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander; |
49 | 52 | import org.jenkinsci.plugins.workflow.support.actions.EnvironmentAction; |
| 53 | +import org.jenkinsci.plugins.workflow.support.pickles.SingleTypedPickleFactory; |
50 | 54 | import org.kohsuke.accmod.Restricted; |
51 | 55 | import org.kohsuke.accmod.restrictions.DoNotUse; |
52 | 56 | import org.kohsuke.stapler.export.Exported; |
53 | 57 | import org.kohsuke.stapler.export.ExportedBean; |
54 | 58 |
|
55 | 59 | @ExportedBean |
56 | | -public class EnvActionImpl extends GroovyObjectSupport implements EnvironmentAction.IncludingOverrides, Serializable, RunAction2 { |
| 60 | +public class EnvActionImpl extends GroovyObjectSupport implements EnvironmentAction.IncludingOverrides, RunAction2 { |
57 | 61 |
|
58 | 62 | private static final Logger LOGGER = Logger.getLogger(EnvActionImpl.class.getName()); |
59 | 63 | private static final long serialVersionUID = 1; |
@@ -199,4 +203,30 @@ public Collection<EnvironmentContributor> getEnvironmentContributors() { |
199 | 203 |
|
200 | 204 | } |
201 | 205 |
|
| 206 | + @Extension public static class EnvActionImplPickleFactory extends SingleTypedPickleFactory<EnvActionImpl> { |
| 207 | + @Override |
| 208 | + protected Pickle pickle(EnvActionImpl object) { |
| 209 | + return new EnvActionImplPickle(); |
| 210 | + } |
| 211 | + } |
| 212 | + |
| 213 | + /** |
| 214 | + * Prevents multiple instances of {@link EnvActionImpl} from existing for a single Pipeline after a Jenkins restart |
| 215 | + * in case {@code env} is serialized into the program. |
| 216 | + */ |
| 217 | + private static class EnvActionImplPickle extends Pickle { |
| 218 | + @Override |
| 219 | + public ListenableFuture<?> rehydrate(FlowExecutionOwner owner) { |
| 220 | + try { |
| 221 | + Queue.Executable executable = owner.getExecutable(); |
| 222 | + if (executable instanceof Run) { |
| 223 | + return Futures.immediateFuture(EnvActionImpl.forRun((Run)executable)); |
| 224 | + } else { |
| 225 | + return Futures.immediateFailedFuture(new IllegalStateException("Invalid executable: " + executable)); |
| 226 | + } |
| 227 | + } catch (IOException e) { |
| 228 | + return Futures.immediateFailedFuture(e); |
| 229 | + } |
| 230 | + } |
| 231 | + } |
202 | 232 | } |
0 commit comments