diff options
author | S.Nishio <nishio@densan-labs.net> | 2016-06-03 00:36:35 +0900 |
---|---|---|
committer | S.Nishio <nishio@densan-labs.net> | 2016-06-03 00:36:35 +0900 |
commit | dc31b18970069ce2943ea8ce293cdcfb6c4045d6 (patch) | |
tree | 6ae11261d1ff4e49ce8150c6fe5b1e94b3f52868 /src/main/java | |
parent | 34849c3c1f9e229bdae47a6f2c7a19317aa18ed9 (diff) | |
parent | 5485845edafde360cd43f035ca329cfe3baba49a (diff) | |
download | bbprb-dc31b18970069ce2943ea8ce293cdcfb6c4045d6.tar.gz |
Merge pull request #88 from frodeaa/security-170-patch
Adapt to SECURITY-170
Diffstat (limited to 'src/main/java')
2 files changed, 40 insertions, 11 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketAdditionalParameterEnvironmentContributor.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketAdditionalParameterEnvironmentContributor.java new file mode 100644 index 0000000..c531ca1 --- /dev/null +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketAdditionalParameterEnvironmentContributor.java @@ -0,0 +1,40 @@ +package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder; + +import hudson.EnvVars; +import hudson.Extension; +import hudson.model.*; + +import java.io.IOException; + +@Extension +public class BitbucketAdditionalParameterEnvironmentContributor extends EnvironmentContributor { + @Override + public void buildEnvironmentFor(Run run, EnvVars envVars, TaskListener taskListener) + throws IOException, InterruptedException { + + BitbucketCause cause = (BitbucketCause) run.getCause(BitbucketCause.class); + if (cause == null) { + return; + } + + putEnvVar(envVars, "sourceBranch", cause.getSourceBranch()); + putEnvVar(envVars, "targetBranch", cause.getTargetBranch()); + putEnvVar(envVars, "repositoryOwner", cause.getRepositoryOwner()); + putEnvVar(envVars, "repositoryName", cause.getRepositoryName()); + putEnvVar(envVars, "pullRequestId", cause.getPullRequestId()); + putEnvVar(envVars, "destinationRepositoryOwner", cause.getDestinationRepositoryOwner()); + putEnvVar(envVars, "destinationRepositoryName", cause.getDestinationRepositoryName()); + putEnvVar(envVars, "pullRequestTitle", cause.getPullRequestTitle()); + putEnvVar(envVars, "pullRequestAuthor", cause.getPullRequestAuthor()); + + } + + private static void putEnvVar(EnvVars envs, String name, String value) { + envs.put(name, getString(value, "")); + } + + private static String getString(String actual, String d) { + return actual == null ? d : actual; + } + +} diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java index 1120aca..aedfb91 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/BitbucketBuildTrigger.java @@ -164,17 +164,6 @@ public class BitbucketBuildTrigger extends Trigger<AbstractProject<?, ?>> { public QueueTaskFuture<?> startJob(BitbucketCause cause) { Map<String, ParameterValue> values = this.getDefaultParameters(); - - values.put("sourceBranch", new StringParameterValue("sourceBranch", cause.getSourceBranch())); - values.put("targetBranch", new StringParameterValue("targetBranch", cause.getTargetBranch())); - values.put("repositoryOwner", new StringParameterValue("repositoryOwner", cause.getRepositoryOwner())); - values.put("repositoryName", new StringParameterValue("repositoryName", cause.getRepositoryName())); - values.put("pullRequestId", new StringParameterValue("pullRequestId", cause.getPullRequestId())); - values.put("destinationRepositoryOwner", new StringParameterValue("destinationRepositoryOwner", cause.getDestinationRepositoryOwner())); - values.put("destinationRepositoryName", new StringParameterValue("destinationRepositoryName", cause.getDestinationRepositoryName())); - values.put("pullRequestTitle", new StringParameterValue("pullRequestTitle", cause.getPullRequestTitle())); - values.put("pullRequestAuthor", new StringParameterValue("pullRequestAuthor", cause.getPullRequestAuthor())); - return this.job.scheduleBuild2(0, cause, new ParametersAction(new ArrayList(values.values())), new RevisionParameterAction(cause.getSourceCommitHash())); } |