forked from aaronjwhiteside/pipeline-github
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from v1v/expose/variable
expose comment and author as environment variables
- Loading branch information
Showing
3 changed files
with
92 additions
and
5 deletions.
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
68 changes: 68 additions & 0 deletions
68
.../java/org/jenkinsci/plugins/pipeline/github/trigger/GitHubEnvironmentVariablesAction.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,68 @@ | ||
package org.jenkinsci.plugins.pipeline.github.trigger; | ||
|
||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.EnvironmentContributor; | ||
import hudson.model.ParameterValue; | ||
import hudson.model.ParametersAction; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
|
||
@Restricted(NoExternalUse.class) | ||
public class GitHubEnvironmentVariablesAction extends ParametersAction { | ||
|
||
private List<ParameterValue> parameters; | ||
|
||
public GitHubEnvironmentVariablesAction(List<ParameterValue> parameters) { | ||
super(parameters); | ||
this.parameters = parameters; | ||
} | ||
|
||
public GitHubEnvironmentVariablesAction(ParameterValue... parameters) { | ||
this(Arrays.asList(parameters)); | ||
} | ||
|
||
@Override | ||
public List<ParameterValue> getParameters() { | ||
return Collections.unmodifiableList(parameters); | ||
} | ||
|
||
@Override | ||
public ParameterValue getParameter(String name) { | ||
for (ParameterValue parameter : parameters) { | ||
if (parameter != null && parameter.getName().equals(name)) { | ||
return parameter; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Extension | ||
public static final class GitHubAdditionalParameterEnvironmentContributor extends EnvironmentContributor { | ||
|
||
@Override | ||
@SuppressWarnings("rawtypes") | ||
public void buildEnvironmentFor(@Nonnull Run run, | ||
@Nonnull EnvVars envs, | ||
@Nonnull TaskListener listener) throws IOException, InterruptedException { | ||
|
||
GitHubEnvironmentVariablesAction action = run.getAction(GitHubEnvironmentVariablesAction.class); | ||
if (action != null) { | ||
for (ParameterValue p : action.getParameters()) { | ||
envs.put(p.getName(), String.valueOf(p.getValue())); | ||
} | ||
} | ||
super.buildEnvironmentFor(run, envs, listener); | ||
} | ||
} | ||
} |
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