forked from nemccarthy/stash-pullrequest-builder-plugin
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 #19 from mrooney/master
expose missing environment variables for JENKINS-34847
- Loading branch information
Showing
2 changed files
with
73 additions
and
21 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
...requestbuilder/stashpullrequestbuilder/StashAditionalParameterEnvironmentContributor.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,55 @@ | ||
package stashpullrequestbuilder.stashpullrequestbuilder; | ||
|
||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.model.*; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
@Extension | ||
public class StashAditionalParameterEnvironmentContributor extends EnvironmentContributor { | ||
private static Set<String> params = | ||
new HashSet<String>(Arrays.asList("sourceBranch", | ||
"targetBranch", | ||
"sourceRepositoryOwner", | ||
"sourceRepositoryName", | ||
"pullRequestId", | ||
"destinationRepositoryOwner", | ||
"destinationRepositoryName", | ||
"pullRequestTitle", | ||
"sourceCommitHash", | ||
"destinationCommitHash")); | ||
|
||
@Override | ||
public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException { | ||
StashCause cause = (StashCause) r.getCause(StashCause.class); | ||
if (cause == null) { | ||
return; | ||
} | ||
ParametersAction pa = r.getAction(ParametersAction.class); | ||
for (String param : params) { | ||
addParameter(param, pa, envs); | ||
} | ||
super.buildEnvironmentFor(r, envs, listener); | ||
} | ||
|
||
private static void addParameter(String key, | ||
ParametersAction pa, | ||
EnvVars envs) { | ||
ParameterValue pv = pa.getParameter(key); | ||
if (pv == null || !(pv instanceof StringParameterValue)) { | ||
return; | ||
} | ||
StringParameterValue value = (StringParameterValue) pa.getParameter(key); | ||
envs.put(key, getString(value.value, "")); | ||
} | ||
|
||
private static String getString(String actual, | ||
String d) { | ||
return actual == null ? d : actual; | ||
} | ||
|
||
|
||
} |
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