Skip to content

Commit 20aced1

Browse files
committed
Add environment variables to every Run caused by StashCause
This should provide the environment variables to pipeline projects.
1 parent 8747cbe commit 20aced1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/main/java/stashpullrequestbuilder/stashpullrequestbuilder/StashAditionalParameterEnvironmentContributor.java

+18-15
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ public class StashAditionalParameterEnvironmentContributor extends EnvironmentCo
1616
public void buildEnvironmentFor(
1717
@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener)
1818
throws IOException, InterruptedException {
19+
Run<?, ?> rootRun;
1920
if (r instanceof AbstractBuild) {
20-
AbstractBuild build = (AbstractBuild) r;
21-
AbstractBuild rootBuild = build.getRootBuild();
21+
AbstractBuild<?, ?> build = (AbstractBuild) r;
22+
rootRun = build.getRootBuild();
23+
} else {
24+
rootRun = (Run<?, ?>) r;
25+
}
2226

23-
StashCause cause = (StashCause) rootBuild.getCause(StashCause.class);
24-
if (cause != null) {
25-
putEnvVar(envs, "sourceBranch", cause.getSourceBranch());
26-
putEnvVar(envs, "targetBranch", cause.getTargetBranch());
27-
putEnvVar(envs, "sourceRepositoryOwner", cause.getSourceRepositoryOwner());
28-
putEnvVar(envs, "sourceRepositoryName", cause.getSourceRepositoryName());
29-
putEnvVar(envs, "pullRequestId", cause.getPullRequestId());
30-
putEnvVar(envs, "destinationRepositoryOwner", cause.getDestinationRepositoryOwner());
31-
putEnvVar(envs, "destinationRepositoryName", cause.getDestinationRepositoryName());
32-
putEnvVar(envs, "pullRequestTitle", cause.getPullRequestTitle());
33-
putEnvVar(envs, "sourceCommitHash", cause.getSourceCommitHash());
34-
putEnvVar(envs, "destinationCommitHash", cause.getDestinationCommitHash());
35-
}
27+
StashCause cause = (StashCause) rootRun.getCause(StashCause.class);
28+
if (cause != null) {
29+
putEnvVar(envs, "sourceBranch", cause.getSourceBranch());
30+
putEnvVar(envs, "targetBranch", cause.getTargetBranch());
31+
putEnvVar(envs, "sourceRepositoryOwner", cause.getSourceRepositoryOwner());
32+
putEnvVar(envs, "sourceRepositoryName", cause.getSourceRepositoryName());
33+
putEnvVar(envs, "pullRequestId", cause.getPullRequestId());
34+
putEnvVar(envs, "destinationRepositoryOwner", cause.getDestinationRepositoryOwner());
35+
putEnvVar(envs, "destinationRepositoryName", cause.getDestinationRepositoryName());
36+
putEnvVar(envs, "pullRequestTitle", cause.getPullRequestTitle());
37+
putEnvVar(envs, "sourceCommitHash", cause.getSourceCommitHash());
38+
putEnvVar(envs, "destinationCommitHash", cause.getDestinationCommitHash());
3639
}
3740

3841
super.buildEnvironmentFor(r, envs, listener);

0 commit comments

Comments
 (0)