|
| 1 | +package com.github.kostyasha.github.integration.multibranch; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import hudson.EnvVars; |
| 7 | +import hudson.Extension; |
| 8 | +import hudson.model.Action; |
| 9 | +import hudson.model.EnvironmentContributor; |
| 10 | +import hudson.model.InvisibleAction; |
| 11 | +import hudson.model.ParameterValue; |
| 12 | +import hudson.model.ParametersAction; |
| 13 | +import hudson.model.Run; |
| 14 | +import hudson.model.TaskListener; |
| 15 | +import hudson.model.Queue.Item; |
| 16 | +import hudson.model.Queue.Task; |
| 17 | +import hudson.model.queue.FoldableAction; |
| 18 | + |
| 19 | +/** |
| 20 | + * Simpler replacement for {@link ParametersAction} that does not stand in the way of 'folding' queue items |
| 21 | + * @author atanasenko |
| 22 | + * |
| 23 | + */ |
| 24 | +public class GitHubParametersAction extends InvisibleAction implements FoldableAction { |
| 25 | + |
| 26 | + private List<ParameterValue> params; |
| 27 | + |
| 28 | + public GitHubParametersAction(List<ParameterValue> params) { |
| 29 | + this.params = params; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public void foldIntoExisting(Item item, Task owner, List<Action> actions) { |
| 34 | + item.addOrReplaceAction(this); |
| 35 | + } |
| 36 | + |
| 37 | + @Extension |
| 38 | + public static class GitHubEnvContributor extends EnvironmentContributor { |
| 39 | + @Override |
| 40 | + public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) throws IOException, InterruptedException { |
| 41 | + GitHubParametersAction action = r.getAction(GitHubParametersAction.class); |
| 42 | + if (action == null) { |
| 43 | + return; |
| 44 | + } |
| 45 | + action.params.forEach(p -> p.buildEnvironment(r, envs)); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | +} |
0 commit comments