get Environment from the parent MatrixBuild if we are in a MatrixRun

This commit is contained in:
Evgeni Golov 2017-04-26 13:18:17 +02:00
parent c1f40c1336
commit cb87235248
1 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,8 @@ package com.dabsquared.gitlabjenkins.environment;
import com.dabsquared.gitlabjenkins.cause.GitLabWebHookCause;
import hudson.EnvVars;
import hudson.Extension;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
import hudson.model.EnvironmentContributor;
import hudson.model.Run;
import hudson.model.TaskListener;
@ -17,7 +19,15 @@ import java.io.IOException;
public class GitLabEnvironmentContributor extends EnvironmentContributor {
@Override
public void buildEnvironmentFor(@Nonnull Run r, @Nonnull EnvVars envs, @Nonnull TaskListener listener) throws IOException, InterruptedException {
GitLabWebHookCause cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class);
GitLabWebHookCause cause = null;
if (r instanceof MatrixRun) {
MatrixBuild parent = ((MatrixRun)r).getParentBuild();
if (parent != null) {
cause = (GitLabWebHookCause) parent.getCause(GitLabWebHookCause.class);
}
} else {
cause = (GitLabWebHookCause) r.getCause(GitLabWebHookCause.class);
}
if (cause != null) {
envs.overrideAll(cause.getData().getBuildVariables());
}