Skip to content

Commit

Permalink
Merge pull request #286 from atanasenko/env_params_folding
Browse files Browse the repository at this point in the history
[scmsource] Allow queue item folding to happen
  • Loading branch information
KostyaSha authored Sep 19, 2018
2 parents 5b45c7c + e8d2637 commit ace06ad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.github.kostyasha.github.integration.multibranch;

import java.io.IOException;
import java.util.List;

import hudson.EnvVars;
import hudson.Extension;
import hudson.model.Action;
import hudson.model.EnvironmentContributor;
import hudson.model.InvisibleAction;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.model.Queue.Item;
import hudson.model.Queue.Task;
import hudson.model.queue.FoldableAction;

/**
* Simpler replacement for {@link ParametersAction} that does not stand in the way of 'folding' queue items
* @author atanasenko
*
*/
public class GitHubParametersAction extends InvisibleAction implements FoldableAction {

private List<ParameterValue> params;

public GitHubParametersAction(List<ParameterValue> params) {
this.params = params;
}

@Override
public void foldIntoExisting(Item item, Task owner, List<Action> actions) {
item.addOrReplaceAction(this);
}

@Extension
public static class GitHubEnvContributor extends EnvironmentContributor {
@Override
public void buildEnvironmentFor(Run r, EnvVars envs, TaskListener listener) throws IOException, InterruptedException {
GitHubParametersAction action = r.getAction(GitHubParametersAction.class);
if (action == null) {
return;
}
action.params.forEach(p -> p.buildEnvironment(r, envs));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import hudson.model.Action;
import hudson.model.CauseAction;
import hudson.model.ParameterValue;
import hudson.model.ParametersAction;
import hudson.model.TaskListener;
import hudson.scm.SCM;
import jenkins.scm.api.SCMHead;
Expand Down Expand Up @@ -257,10 +256,8 @@ protected List<Action> retrieveActions(@Nonnull SCMRevision revision, @CheckForN
GitHubCause<?> cause = gitHubSCMRevision.getCause();
if (nonNull(cause)) {
List<ParameterValue> params = new ArrayList<>();
List<String> safeParams = new ArrayList<>();
cause.fillParameters(params);
params.forEach(p -> safeParams.add(p.getName()));
return Arrays.asList(new CauseAction(cause), new ParametersAction(params, safeParams));
return Arrays.asList(new CauseAction(cause), new GitHubParametersAction(params));
}

return Collections.emptyList();
Expand Down

0 comments on commit ace06ad

Please sign in to comment.